c# listview
-
hi am developing c# winforms application. my requirement is basedon tag_id(sEPC) ,i need to get the data from inventory table and populate that data(tagid,categoryid,productid,productname,gateid and remarks) on listview next check the transaction table whether the out time is null. if out_time is null ,then update the record using tag_id. if not null then insert the new record in transaction table. here is the code: string query = "SELECT tag_id,category_id,product_id,product_name,gate_id,remarks FROM inventory where tag_id Like '" + sEPC + "'"; MySqlCommand cmd; MySqlDataReader rdr; MySqlConnection connection = new MySqlConnection(MyConnectionString); connection.Open(); // DataTable dt = new DataTable(); cmd = new MySqlCommand(query, connection); rdr = cmd.ExecuteReader(); /*Received Epc matched in the Inventory Table */ if (rdr != null) { String s2 = DateTime.Now.ToString("yyyy-MM-dd HH:MM:ss").Trim(); // ListView1_EPC.Items[j].Remove(); if (rdr.Read()) { String a1; cnt = ListView1_EPC.Items.Count; ListViewItem item = new ListViewItem(rdr.GetString(0)); // cnt = ListView1_EPC.Items.Count; item.SubItems.Add(rdr.GetString(1)); item.SubItems.Add(rdr.GetString(2)); item.SubItems.Add(rdr.GetString(3)); item.SubItems.Add(rdr.GetString(4)); item.SubItems.Add(""); item.SubItems.Add(""); item.SubItems.Add(rdr.GetString(5)); //item.SubItems[Remarks.Index].Text = rdr.GetString(5); ListView1_EPC.Items.Add(item); rdr.Close(); cnt = ListView1_EPC.Items.Count; MessageBox.Show("cnt:"+cnt); string query1 = "SELECT tag_id,category_id,product_id,product_name,gate_id,rema
-
hi am developing c# winforms application. my requirement is basedon tag_id(sEPC) ,i need to get the data from inventory table and populate that data(tagid,categoryid,productid,productname,gateid and remarks) on listview next check the transaction table whether the out time is null. if out_time is null ,then update the record using tag_id. if not null then insert the new record in transaction table. here is the code: string query = "SELECT tag_id,category_id,product_id,product_name,gate_id,remarks FROM inventory where tag_id Like '" + sEPC + "'"; MySqlCommand cmd; MySqlDataReader rdr; MySqlConnection connection = new MySqlConnection(MyConnectionString); connection.Open(); // DataTable dt = new DataTable(); cmd = new MySqlCommand(query, connection); rdr = cmd.ExecuteReader(); /*Received Epc matched in the Inventory Table */ if (rdr != null) { String s2 = DateTime.Now.ToString("yyyy-MM-dd HH:MM:ss").Trim(); // ListView1_EPC.Items[j].Remove(); if (rdr.Read()) { String a1; cnt = ListView1_EPC.Items.Count; ListViewItem item = new ListViewItem(rdr.GetString(0)); // cnt = ListView1_EPC.Items.Count; item.SubItems.Add(rdr.GetString(1)); item.SubItems.Add(rdr.GetString(2)); item.SubItems.Add(rdr.GetString(3)); item.SubItems.Add(rdr.GetString(4)); item.SubItems.Add(""); item.SubItems.Add(""); item.SubItems.Add(rdr.GetString(5)); //item.SubItems[Remarks.Index].Text = rdr.GetString(5); ListView1_EPC.Items.Add(item); rdr.Close(); cnt = ListView1_EPC.Items.Count; MessageBox.Show("cnt:"+cnt); string query1 = "SELECT tag_id,category_id,product_id,product_name,gate_id,rema
-
hi am developing c# winforms application. my requirement is basedon tag_id(sEPC) ,i need to get the data from inventory table and populate that data(tagid,categoryid,productid,productname,gateid and remarks) on listview next check the transaction table whether the out time is null. if out_time is null ,then update the record using tag_id. if not null then insert the new record in transaction table. here is the code: string query = "SELECT tag_id,category_id,product_id,product_name,gate_id,remarks FROM inventory where tag_id Like '" + sEPC + "'"; MySqlCommand cmd; MySqlDataReader rdr; MySqlConnection connection = new MySqlConnection(MyConnectionString); connection.Open(); // DataTable dt = new DataTable(); cmd = new MySqlCommand(query, connection); rdr = cmd.ExecuteReader(); /*Received Epc matched in the Inventory Table */ if (rdr != null) { String s2 = DateTime.Now.ToString("yyyy-MM-dd HH:MM:ss").Trim(); // ListView1_EPC.Items[j].Remove(); if (rdr.Read()) { String a1; cnt = ListView1_EPC.Items.Count; ListViewItem item = new ListViewItem(rdr.GetString(0)); // cnt = ListView1_EPC.Items.Count; item.SubItems.Add(rdr.GetString(1)); item.SubItems.Add(rdr.GetString(2)); item.SubItems.Add(rdr.GetString(3)); item.SubItems.Add(rdr.GetString(4)); item.SubItems.Add(""); item.SubItems.Add(""); item.SubItems.Add(rdr.GetString(5)); //item.SubItems[Remarks.Index].Text = rdr.GetString(5); ListView1_EPC.Items.Add(item); rdr.Close(); cnt = ListView1_EPC.Items.Count; MessageBox.Show("cnt:"+cnt); string query1 = "SELECT tag_id,category_id,product_id,product_name,gate_id,rema
I'm missing field-names in your update query. How does MySQL know which column you want to push each value into?
UPDATE [tablename]
SET col1 = value1,
col2 = value2I can only see values in your query, not the fieldnames. Further you'd like to make that a parameterized query, to prevent attacks on your application using sql-injection. And you should wrap those disposables in a
using
-block. ..and you might want to do simply a "SELECT COUNT(*)" to test whether the record exists; then you can useExecuteScalar
, which would be a bit more efficient.Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
I'm missing field-names in your update query. How does MySQL know which column you want to push each value into?
UPDATE [tablename]
SET col1 = value1,
col2 = value2I can only see values in your query, not the fieldnames. Further you'd like to make that a parameterized query, to prevent attacks on your application using sql-injection. And you should wrap those disposables in a
using
-block. ..and you might want to do simply a "SELECT COUNT(*)" to test whether the record exists; then you can useExecuteScalar
, which would be a bit more efficient.Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
it's ok. thanq But am getting error as ArgumentOutORange exception at item.SubItems[INTime.Index].Text = s2; Listview consists 0nly 7 colums.
string query = "SELECT tag_id,category_id,product_id,product_name,gate_id,remarks FROM inventory where tag_id Like '" + sEPC + "'";
MySqlCommand cmd;
MySqlDataReader rdr;
MySqlConnection connection = new MySqlConnection(MyConnectionString);
connection.Open();// DataTable dt = new DataTable(); cmd = new MySqlCommand(query, connection); rdr = cmd.ExecuteReader(); /\*Received Epc matched in the Inventory Table \*/ if (rdr != null) { String s2 = DateTime.Now.ToString("yyyy-MM-dd HH:MM:ss").Trim(); // ListView1\_EPC.Items\[j\].Remove(); if (rdr.Read()) { cnt = ListView1\_EPC.Items.Count; ListViewItem item = new ListViewItem(rdr.GetString(0)); cnt = ListView1\_EPC.Items.Count; item.SubItems.Add(rdr.GetString(1)); item.SubItems.Add(rdr.GetString(2)); item.SubItems.Add(rdr.GetString(3)); item.SubItems.Add(rdr.GetString(4)); // item.SubItems.Add(s2); // item.SubItems.Add(s2); //item.SubItems\[OUTTime.Index\].Text = rdr.GetString(5); item.SubItems.Add(rdr.GetString(5)); ListView1\_EPC.Items.Add(item); cnt = ListView1\_EPC.Items.Count; rdr.Close(); string query1 = "SELECT tag\_id,category\_id,product\_id,product\_name,gate\_id,remarks FROM transaction where tag\_id Like '" + sEPC + "' AND out\_time=NULL"; MySqlCommand cmd1= new MySqlCommand(query1,connection); MySqlDataReader rdr1 = cmd1.ExecuteReader(); if (rdr1 != null) { item.SubItems\[INTime.Index\].Text = s2;
-
it's ok. thanq But am getting error as ArgumentOutORange exception at item.SubItems[INTime.Index].Text = s2; Listview consists 0nly 7 colums.
string query = "SELECT tag_id,category_id,product_id,product_name,gate_id,remarks FROM inventory where tag_id Like '" + sEPC + "'";
MySqlCommand cmd;
MySqlDataReader rdr;
MySqlConnection connection = new MySqlConnection(MyConnectionString);
connection.Open();// DataTable dt = new DataTable(); cmd = new MySqlCommand(query, connection); rdr = cmd.ExecuteReader(); /\*Received Epc matched in the Inventory Table \*/ if (rdr != null) { String s2 = DateTime.Now.ToString("yyyy-MM-dd HH:MM:ss").Trim(); // ListView1\_EPC.Items\[j\].Remove(); if (rdr.Read()) { cnt = ListView1\_EPC.Items.Count; ListViewItem item = new ListViewItem(rdr.GetString(0)); cnt = ListView1\_EPC.Items.Count; item.SubItems.Add(rdr.GetString(1)); item.SubItems.Add(rdr.GetString(2)); item.SubItems.Add(rdr.GetString(3)); item.SubItems.Add(rdr.GetString(4)); // item.SubItems.Add(s2); // item.SubItems.Add(s2); //item.SubItems\[OUTTime.Index\].Text = rdr.GetString(5); item.SubItems.Add(rdr.GetString(5)); ListView1\_EPC.Items.Add(item); cnt = ListView1\_EPC.Items.Count; rdr.Close(); string query1 = "SELECT tag\_id,category\_id,product\_id,product\_name,gate\_id,remarks FROM transaction where tag\_id Like '" + sEPC + "' AND out\_time=NULL"; MySqlCommand cmd1= new MySqlCommand(query1,connection); MySqlDataReader rdr1 = cmd1.ExecuteReader(); if (rdr1 != null) { item.SubItems\[INTime.Index\].Text = s2;