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.

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

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

IS the above code correct???

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+" '

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 + "'"

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;

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+"' ";

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 3 Years Ago by mike_2000_17: Fixed formatting

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.