Click here to Skip to main content
15,890,579 members
Home / Discussions / C#
   

C#

 
QuestionHELp needed Pin
unlucky_dreamer5-Aug-09 11:58
unlucky_dreamer5-Aug-09 11:58 
AnswerRe: HELp needed Pin
Luc Pattyn5-Aug-09 12:23
sitebuilderLuc Pattyn5-Aug-09 12:23 
GeneralRe: HELp needed Pin
unlucky_dreamer5-Aug-09 12:26
unlucky_dreamer5-Aug-09 12:26 
AnswerRe: HELp needed Pin
Christian Graus5-Aug-09 12:24
protectorChristian Graus5-Aug-09 12:24 
GeneralRe: HELp needed Pin
unlucky_dreamer5-Aug-09 12:29
unlucky_dreamer5-Aug-09 12:29 
GeneralRe: HELp needed Pin
Christian Graus5-Aug-09 13:20
protectorChristian Graus5-Aug-09 13:20 
GeneralRe: HELp needed Pin
unlucky_dreamer6-Aug-09 11:31
unlucky_dreamer6-Aug-09 11:31 
QuestionAssigning a SQL query result to a variable Pin
JohnQuar15-Aug-09 11:44
JohnQuar15-Aug-09 11:44 
Hello,

I have a very simple query SELECT newid(), and I want to take the result of this query and assign it a variable so I can use it as a unique ID and use that again in another query. I am having trouble saving the actual variable. Can anyone help? Here is what I have so far. I am also pretty sure that my ID.Close() is in the wrong location. Let me kno what you think.

Session["userName"] = "JMQ";
// create a new SqlConnection object with the appropriate connection string
SqlConnection sqlConn = new SqlConnection("Data Source=localhost;Initial Catalog=Cost_Model;Integrated Security=True");

//Open the connection
sqlConn.Open();

String result;

//Create unique ID
SqlCommand sqlComm1 = new SqlCommand("SELECT newid()", sqlConn);
SqlDataReader ID = sqlComm1.ExecuteReader(CommandBehavior.CloseConnection);

//Close the connection
ID.Close();

sqlConn.Open();
SqlCommand sqlComm2 = new SqlCommand(
    "SELECT * INTO ##tempFAR15_" + Session["userName"] + "_" + ID + " FROM FN_FAR15(1)",
    sqlConn);
SqlDataReader r = sqlComm2.ExecuteReader(CommandBehavior.CloseConnection);

r.Close();

Response.Redirect("FAR15.aspx");


I want to take the result from the 1st query which I (probably innapropriately have labeled as ID) and then use ID in teh second query. Thanks ALOT!!
AnswerRe: Assigning a SQL query result to a variable Pin
Christian Graus5-Aug-09 12:25
protectorChristian Graus5-Aug-09 12:25 
GeneralRe: Assigning a SQL query result to a variable Pin
JohnQuar15-Aug-09 15:16
JohnQuar15-Aug-09 15:16 
AnswerRe: Assigning a SQL query result to a variable Pin
PIEBALDconsult5-Aug-09 17:08
mvePIEBALDconsult5-Aug-09 17:08 
GeneralRe: Assigning a SQL query result to a variable Pin
JohnQuar16-Aug-09 4:49
JohnQuar16-Aug-09 4:49 
GeneralRe: Assigning a SQL query result to a variable Pin
PIEBALDconsult6-Aug-09 12:38
mvePIEBALDconsult6-Aug-09 12:38 
GeneralLearning C# syntax for a Trading Platform Pin
jelamiju15-Aug-09 11:27
jelamiju15-Aug-09 11:27 
GeneralRe: Learning C# syntax for a Trading Platform Pin
Christian Graus5-Aug-09 11:41
protectorChristian Graus5-Aug-09 11:41 
GeneralRe: Learning C# syntax for a Trading Platform Pin
jelamiju16-Aug-09 5:44
jelamiju16-Aug-09 5:44 
Question[Message Deleted] Pin
tamir9015-Aug-09 11:27
tamir9015-Aug-09 11:27 
AnswerRe: Error - protection level Pin
Christian Graus5-Aug-09 11:41
protectorChristian Graus5-Aug-09 11:41 
AnswerRe: [Message Deleted] Pin
Christian Graus5-Aug-09 13:20
protectorChristian Graus5-Aug-09 13:20 
QuestionControls.Add() Problem Pin
will kirkby5-Aug-09 10:02
will kirkby5-Aug-09 10:02 
AnswerRe: Controls.Add() Problem Pin
Luc Pattyn5-Aug-09 10:27
sitebuilderLuc Pattyn5-Aug-09 10:27 
GeneralRe: Controls.Add() Problem Pin
will kirkby5-Aug-09 10:43
will kirkby5-Aug-09 10:43 
GeneralRe: Controls.Add() Problem Pin
Luc Pattyn5-Aug-09 11:09
sitebuilderLuc Pattyn5-Aug-09 11:09 
GeneralRe: Controls.Add() Problem Pin
MarkB7775-Aug-09 14:20
MarkB7775-Aug-09 14:20 
GeneralRe: Controls.Add() Problem Pin
Luc Pattyn5-Aug-09 14:27
sitebuilderLuc Pattyn5-Aug-09 14:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.