Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
DataSet ds = new DataSet();
            try
            {
                MySqlConnection con = new MySqlConnection("Server=localhost;UID=root;Database=db_cignal");
                con.Open();
                MySqlCommand command = con.CreateCommand();
                command.CommandText = "Select * from inventory where Product like @cb ";
                command.Parameters.Add("@cb", MySqlDbType.VarChar, 20).Value = "%" + cbProductDescription.SelectedItem.ToString();
                MySqlDataAdapter da = new MySqlDataAdapter();
                da.SelectCommand = command;
                da.Fill(ds);
                da.Update(ds);
                con.Close();

            }
            catch (Exception r)
            {
                MessageBox.Show(r.ToString());
            }
Posted
Updated 21-Feb-15 23:24pm
v2

1 solution

Debug your code. You are accessing a property of an object that is null.
 
Share this answer
 
Comments
_bluRe_ 22-Feb-15 1:45am    
yaa. the problem is here. cbProductDescription.SelectedItem.ToString(); even is i instantiate the selected value to a string, still same.
_bluRe_ 22-Feb-15 1:46am    
i was trying to do a search here :)
Abhinav S 22-Feb-15 1:53am    
SelectedItem is null aNd you are doing a toString() to that.

Try Convert.ToString() instead.
_bluRe_ 22-Feb-15 1:59am    
still the same. i did something like this this.cbProductDescription.GetItemText(this.cbProductDescription.SelectedItem) no error but nothing happens as well
_bluRe_ 22-Feb-15 2:00am    
DataSet ds = new DataSet();
try
{
MySqlConnection con = new MySqlConnection("connection...");
con.Open();
MySqlCommand command = con.CreateCommand();
command.CommandText = "Select * from inventory where Product like @cb ";
command.Parameters.Add("@cb", MySqlDbType.VarChar, 20).Value = "%" + this.cbProductDescription.GetItemText(this.cbProductDescription.SelectedItem);
MySqlDataAdapter da = new MySqlDataAdapter();
command.ExecuteNonQuery();
da.SelectCommand = command;
da.Fill(ds);
da.Update(ds);
con.Close();

}
catch (Exception r)
{
MessageBox.Show(r.ToString());
}

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