SqlConnection XX=new SqlConnection(Xintong);
            int Lh = listView1.Items.Count;
            for (int j = 0; j < Lh; j++)
            {
                XX.Open();                String num = listView1.Items[j].SubItems[0].ToString();
                String name = listView1.Items[j].SubItems[1].ToString();
                String price = listView1.Items[j].SubItems[2].ToString();
                String date = listView1.Items[j].SubItems[3].ToString();
                String count = listView1.Items[j].SubItems[4].ToString();
                String ch = listView1.Items[j].SubItems[5].ToString();                String Xql = "insert into 商品查询表 values('" + num + "','" + name + "','" + price + "','" + date + "','" + count + "','" + ch + "')";
                SqlCommand XXcom = new SqlCommand(Xql, XX);
                XX.Close();
            }
我哪些错了?

解决方案 »

  1.   

    少了一句执行语句
    XXcom.ExcuteNOQuery()
      

  2.   


    SqlConnection XX=new SqlConnection(Xintong);  XX.Open();  
    int Lh = listView1.Items.Count;
      for (int j = 0; j < Lh; j++)
      {  String num = listView1.Items[j].SubItems[0].ToString();
      String name = listView1.Items[j].SubItems[1].ToString();
      String price = listView1.Items[j].SubItems[2].ToString();
      String date = listView1.Items[j].SubItems[3].ToString();
      String count = listView1.Items[j].SubItems[4].ToString();
      String ch = listView1.Items[j].SubItems[5].ToString();  String Xql = "insert into 商品查询表 values('" + num + "','" + name + "','" + price + "','" + date + "','" + count + "','" + ch + "')";
      SqlCommand XXcom = new SqlCommand(Xql, XX);
       int i=xxcom.ExcuteNonQuery();
       if(i!=1){//log}
      }
    XX.Close();