Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i need help. when i click the button and then this error is comming.

"object reference not set to an instance of an object on submit button "


C#
try
        {
            btnUpload.Visible = true;

            con = new SqlConnection("Data Source=.;Initial Catalog=DSIIDC2;Integrated Security=True");
            con.Open();
            string str = "insert into addcaasedetails(caseno,casetype) values(" + txtcaseno.Text + ",'" + txtcasetype.Text + "')";
            cmd = new SqlCommand(str, con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);


            if (ds.Tables["addcaasedetails"] == txtcaseno.Text && ds.Tables["addcaasedetails"].ToString()==txtcasetype.Text.ToString())
            {
                btnUpload.Visible = false;
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
Posted
Updated 25-May-15 21:18pm
v2
Comments
Herman<T>.Instance 26-May-15 3:19am    
What have you tried? Did you debug your source code? Which line causes the error?

1 solution

The best advice for such of error is to use debugger. So, debug your programm and check what object is null.
See past Sergey's answers too[^] for further details.


Note: you're trying to insert data, so... you heave to use ExecuteNonQuery method[^].

To be able to fetch data, use proper SELECT statement, then you'll be able to use DataSet, DataAdapter, etc.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900