0

Hey Guys,
I have a textbox in which a ID is stored. ID has type int in the database.
I want to compare this Textbox ID with the ID in the databse.
I tried to use:
int ID=Convert.ToInt32("TExtboxID.text")
I got an error:
NullReference Exception was handled by Usercode

Please help.

4
Contributors
11
Replies
12
Views
7 Years
Discussion Span
Last Post by anuj_sharma
0

you need not to put TextBoxID.Text in double quotes

as C# is case sensitive ,make sure TextBoxID.Text is written in correct case

it will be written as:

int i = Convert.ToInt32(TextBoxID.Text);

just check the ID of ur textbox and write it in proper case

0

int id = Convert.ToInt32(GetID.Text);
string CommandText = "SELECT * FROM table1 WHERE emp_bookid=id ";

IS the above code correct???

0

hi you can modify it as follows.

string CommandText = "SELECT * FROM table1 WHERE emp_bookid='"+id+"' ";

Let me know if you face any problem with this.


// id syntax in clear way = ' "+id+" '

0

int id = Convert.ToInt32(GetID.Text);
string CommandText = "SELECT * FROM table1 WHERE emp_bookid=id ";

IS the above code correct???

If emp_bookid is a numeric column and GetID is the name of the TextBox control

string CommandText = "SELECT * FROM table1 WHERE emp_bookid = " + GetID.Text

If a varchar or char type column,

string CommandText = "SELECT * FROM table1 WHERE emp_bookid = '" + GetID.Text + "'"
0

I've tried all the above code but it's still giving an exception.
This is the code:
int id = Convert.ToInt32(GetID.Text);
string CommandText = "UPDATE booking_projdetails SET book_status= '" + NewStatus.Text + "' WHERE emp_bookid=' " + id;

0

hi try with the following code.

int id = Convert.ToInt32(GetID.Text);
string CommandText = "UPDATE booking_projdetails SET book_status= '" + NewStatus.Text + "' WHERE emp_bookid='"+id+"' ";
0

Still giving an exception.
I tried :

try
{
string cmd = "SELECT * FROM booking_projdetails WHERE emp_bookid=" + GetID.Text;
            SqlCommand myCommand = new SqlCommand(cmd, myConnection);
            SqlDataReader dr;
            dr = myCommand.ExecuteReader();
            if (dr.Read())
            {
                Label2.Text = dr[0].ToString();

            }

            string CommandText = "UPDATE booking_projdetails SET book_status= '" + NewStatus.Text + "'  WHERE emp_bookid='"+Label2.Text+"' ";
}
catch(Exception ex)
{
    throw(ex)
}

Edited by mike_2000_17: Fixed formatting

0

please put the break points and see whether you r getting the value in getid.text ?? if not it will through exception and check the defintion of sqlfields like empid as int or not...

if it is not int then u need to use like operator in ur sql query...

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.