Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. c# listview

c# listview

Scheduled Pinned Locked Moved C#
csharpdatabasewinformsannouncement
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 10263519
    wrote on last edited by
    #1

    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

    L 2 Replies Last reply
    0
    • M Member 10263519

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Could you put the code in pre tags? (you can use the "code" button) It's a little annoying to read this way.

      1 Reply Last reply
      0
      • M Member 10263519

        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

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        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 = value2

        I 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 use ExecuteScalar, which would be a bit more efficient.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        M 1 Reply Last reply
        0
        • L Lost User

          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 = value2

          I 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 use ExecuteScalar, which would be a bit more efficient.

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

          M Offline
          M Offline
          Member 10263519
          wrote on last edited by
          #4

          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;
          
          L 1 Reply Last reply
          0
          • M Member 10263519

            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;
            
            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Member 10263519 wrote:

            But am getting error as ArgumentOutORange exception at
            item.SubItems[INTime.Index].Text = s2;

            Add a "Debug.WriteLine(INTime.Index)", and verify that you got the right column.

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups