-
listbox to database
hi...
i have a checklistbox, when the user clicks an item in the checklist it is added into a listbox...
i want it to store the items in the listbox into the database...
i tried using listBox.tex., but it seems that nothin is bein stored into the column in the database.
pls help
-
How about storing listbox content in a flat file !!
otherwise , show the code that's not working for you .
-
listbox to database
wooo...im lost....whats a flat file...and i guess i cant do that 'cos thats not gonna go down well with my client..
anyways
here's my code
Code:
private void btnSend_Click(object sender, System.EventArgs e)
{
//string med = (string) InsListBox.Items.ToString();
//MessageBox.Show(med.ToString());
try
{
oleDbConnection1.Open();
//if(QuantityListBox.Text != "" && InsListBox.Text != "")
//{
oleDbDataAdapter2.InsertCommand.CommandText = "INSERT INTO DiagPhar ([Acct ID], [Trans ID], Medication, Instructions, Quantity) VALUES ('"+txtAcctID.Text+"' , '"+txtTranID.Text+"' , '"+MedListBox.Text+"' , '"+InsListBox.Text+"' , '"+QuantityListBox.Text+"')";
oleDbDataAdapter2.InsertCommand.ExecuteNonQuery();
MessageBox.Show("Patient's prescription has been sent to the Pharmacy department" , "Information");
//}
//else
//{
// MessageBox.Show("All Text Boxes Should be Filled with Information","Reminder");
//}
}
catch (Exception SendError)
{
MessageBox.Show(SendError.ToString());
}
finally
{
oleDbConnection1.Close();
}
well is there a way where u can take whats in listbox1 and put it into a string.....that way i can store the string into the database..right?...can u show me how do i do that
-
Flat file is like a text file ....:D .
Are you getting any error in the above snippet code ?
-
no error at all..
thats the funny thing...there's no error at all....it processes well only thing is that the columns in the database that are s'pose to be filled with information from the listbox is empty....
the other way i can do this is have a textbox instead of a listbox...but how do i transfer from one textbox to another?..
-
To make sure that code which follow the if structure is executed , make your selection in the listbox and checklistbox , then remove the if statement and try .