problem in inserting data by using checkedlistbox in database

Reply

Join Date: Oct 2009
Posts: 5
Reputation: sivananda2009 is an unknown quantity at this point 
Solved Threads: 0
sivananda2009 sivananda2009 is offline Offline
Newbie Poster

problem in inserting data by using checkedlistbox in database

 
0
  #1
Oct 20th, 2009
  1. private void insertbtn_Click(object sender, EventArgs e)
  2. {
  3. string name = textBox1.Text.ToString();
  4. string course;
  5.  
  6. for (int i = 0; i < checkedListBox1.CheckedItems.Count; i++)
  7. {
  8. course += checkedListBox1.CheckedItems[i].ToString() + " ";
  9. }
  10.  
  11.  
  12. string constring = "PROVIDER= MSDAORA;USER ID = SYSTEM; PASSWORD = mca";
  13. string query = "insert into checkapp1 values('" + name + "','" + course+ "')";
  14. cn = new OleDbConnection(constring);
  15. cn.Open();
  16. cm = new OleDbCommand(query, cn);
  17. cm.ExecuteNonQuery();
  18. MessageBox.Show("data inserted");
  19. }
problem in inserting data by this code. showing a error"unassigned value 'course' is used". please verify and correct it.
Last edited by sivananda2009; Oct 20th, 2009 at 8:39 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 977
Reputation: DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough 
Solved Threads: 224
DdoubleD DdoubleD is offline Offline
Posting Shark
 
0
  #2
Oct 20th, 2009
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...
Last edited by DdoubleD; Oct 20th, 2009 at 8:55 am.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,793
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 698
Sponsor
Featured Poster
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast
 
0
  #3
Oct 20th, 2009
DdoubleD is right. To elaborate more on the issue take this for example:
  1. string s;
  2. 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:
  1. string s = string.Empty;
  2. s += "abc";
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 380 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC