I hover the mouse on t below, and do not see the same effect like you.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
I see that UserID0.Value is with the proper value 18 and there is the existing record with INT column user_id having the value 18. But it is not getting the record by the following command. Why?
SqlCommand cmd = new SqlCommand("SELECT top 1 ... FROM [user_master] where [user_id]=@par_id", conn);
if (UserID0.Value != null)
{
cmd.Parameters.Add("@par_id", SqlDbType.Int).Value = Convert.ToInt32(UserID0.Value);
}
Maybe there is a problem in the rest of the code?
Hi,
I further have the codes like
SqlDataReader reader;
reader = cmd.ExecuteReader();
if (reader.HasRows)
{
reader.Read();
...
to retrieve the record. But it is not getting the record expectedly.
@Peter_1985 , Does it return true or false for reader.HasRows property? If you execute the above query with proper value 18 in the ssms, Could you see some records in the ssms?
The same query is returning the record, with the value 18, within SSMS. I do not know it does not get into the part (of "if (reader.HasRows)").
@Peter_1985 , you could write the code bool t=reader.HasRows;
, to check the value of reader.HasRows.
Yes, I put the code below. But it does not get into if part.
bool t = reader.HasRows;
if (t)
{
reader.Read();
@Peter_1985 , you could output the t value by using the code Console.WriteLine(t);
or MessageBox.Show(t.ToString());
.
Do you get a row if you temporarily remove the WHERE part?
I cannot capture the value by the way below. I tried to remove where clause of the query but no help.
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "ShowMessage('0531aa " + t.ToString() + "');", true);
@Peter_1985 , you could set a breakpoint for the code and put mouse on the variable of t after you executing the code.
When debugging it, how to see the value of t of the following line?
bool t = reader.HasRows;
@Peter_1985 , you could put mouse put on the t variable. Also, you could choose t then right click choose Add watch to check the value of t.
Hi,
What to press below?
@Peter_1985 , Please ensure that your program is running then you could press F10 to execute the code statement by statement.
Like the following:
Can I know what you press on t, on the line "bool t ..."?
@ Jackson1990-7147, just use mouse to choose t without pressing something.
What is returned when hard-coding the SQL ?
SELECT top 1 ... FROM [user_master] where [user_id]=18
I hover the mouse on t below, and do not see the same effect like you.
@Peter_1985 , Please ensure that your app is running then please use F10 to execute your program. By the way, what is your current project?
I press the following button to start testing the project. I am using VS 2019.
Is the following the reason of the issue, but "reader" was declared already?
@Peter_1985 , based on your picture, I guess that your app is a asp.net webform app, right?
Yes, correct
Thanks to all.
How to mark this thread as resolved?
Hi @Peter_1985 ,
You can post your workaround as an answer and click Accept Answer
No way to mark one of the replies in above, as the answer?
Hi @Peter_1985 ,
You can click "More" then click "convert to answer", and finally click Accept Answer.
thanks a lot!