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 Anuj,
If your issue has solved please mark it as solved.

Regards,
Kameswari

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)
}

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...

Post your error message so that it will help to identify the issue.

Thnx guys, the problem has been solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.