0
private void insertbtn_Click(object sender, EventArgs e)
        {
            string name = textBox1.Text.ToString();
            string course;
           
            for (int i = 0; i < checkedListBox1.CheckedItems.Count; i++)
            {
                course += checkedListBox1.CheckedItems[i].ToString() + " ";
            }
               
         
            string constring = "PROVIDER= MSDAORA;USER ID = SYSTEM; PASSWORD = mca";
            string query = "insert into checkapp1 values('" + name + "','" + course+ "')";
            cn = new OleDbConnection(constring);
            cn.Open();
            cm = new OleDbCommand(query, cn);
            cm.ExecuteNonQuery();
            MessageBox.Show("data inserted");
        }

problem in inserting data by this code. showing a error"unassigned value 'course' is used". please verify and correct it. :(

Edited by sivananda2009: n/a

3
Contributors
2
Replies
6
Views
7 Years
Discussion Span
Last Post by sknake
0

the error is very clear... assign a value to your course variable eg. string course = "some text"; EIDT: I assume you have no checkbox selections, but by modifying/initializing the course declaration this error should go away...

Edited by DdoubleD: n/a

0

DdoubleD is right. To elaborate more on the issue take this for example:

string s;
s += "abc";

Now you're appending a value to s, but what is s? It was never assigned a value thus you have the problem. What you can do:

string s = string.Empty;
s += "abc";
This topic has been dead for over six months. 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.