I work in c# windows form vs2015
Problem
How to select multiple item from database based on list box multiple select ?
Details
I set listbox 1 control property selection mode to Multi Simple
code below select only one item selected from list box and work without any problem but select only one item
but if i need to multi select for list box How to changes my code below
- public DataTable ShowaSpecificSerial(string SerialNo)
- {
-
- SqlConnection con = new SqlConnection(connection);
-
-
- con.Open();
- string str = "select * from View_showdata where SerialNo=@SerialNo";
- SqlCommand com = new SqlCommand();
- com = new SqlCommand(str, con);
- com.Parameters.AddWithValue("@SerialNo", SerialNo);
- SqlDataAdapter oledbda = new SqlDataAdapter();
- oledbda = new SqlDataAdapter(com);
- DataSet ds = new DataSet();
- ds = new DataSet();
- oledbda.Fill(ds, "View_showdata");
- con.Close();
- DataTable dt = new DataTable();
- dt = ds.Tables["View_showdata"];
- return dt;
-
-
- }public DataTable ShowaSpecificSerial(string SerialNo)
- {
-
- SqlConnection con = new SqlConnection(connection);
-
-
- con.Open();
- string str = "select * from View_showdata where SerialNo=@SerialNo";
- SqlCommand com = new SqlCommand();
- com = new SqlCommand(str, con);
- com.Parameters.AddWithValue("@SerialNo", SerialNo);
- SqlDataAdapter oledbda = new SqlDataAdapter();
- oledbda = new SqlDataAdapter(com);
- DataSet ds = new DataSet();
- ds = new DataSet();
- oledbda.Fill(ds, "View_showdata");
- con.Close();
- DataTable dt = new DataTable();
- dt = ds.Tables["View_showdata"];
- return dt;
-
-
- }
under button i write following- private void button5_Click(object sender, EventArgs e)
- {
- string root = @"D:\Temp";
-
-
- if (!Directory.Exists(root))
- {
-
- Directory.CreateDirectory(root);
-
- }
- Class1 CLS = new Class1();
- DataTable dt = CLS.ShowaSpecificSerial(listBox3.SelectedValue.ToString());
-
- for (int i = 0; i <= Convert.ToInt32(dt.Rows.Count) - 1; i++)
- {
- txt = "UserID" + dt.Rows[i][0] + "ProductNo" + dt.Rows[i][1] + "Firm Name" + dt.Rows[i][2] + "BtachNo" + dt.Rows[i][3] + "SerialNo" + dt.Rows[i][4];
-
- dm.DM(txt, Color.FromName(comboBox1.SelectedItem.ToString()), Color.White).Save(root + "\\" + dt.Rows[i][4] + ".emf", System.Drawing.Imaging.ImageFormat.Emf);
- }
- }
Sample data to view View_showdata :
UserID Product Firm BatchNo SerialNo
Ali | Parasitemol | Farco | 2099 | 000055 |
Ali | ColdFlue | Farco | 2998 | 01112 |
Ali | ColdFlue | Farco | 2998 | 08888866 |
| | | | |
Result
suppose i make multi select to list box to serial no to 000055 and 08888866
the result must done is create two files image datamatrix with name 000055 and 08888866 in E : /Temp
and when read it by scanner or mobile read data following to every serial selected
file name 08888866 when read it the data must have
Ali | ColdFlue | Farco | 2998 | 08888866 |
so that How to change my code above to accept multi select from database also
according to list box it accept multi select but not from database