日期:2014-05-17  浏览次数:20786 次

C# 连接数据库的问题
我有四个label去记录生成的数,然后想把这四个数插入到数据库里.但是有错误. 帮我看看哪里错了? 谢谢了





string Sql = "INSERT INTO Table3 (Win,Draw,Lose,Total) VALUES ('" + Label15.Text + "','" + Label16.Text + "','" + Label17.Text + "','" + Label18.Text + "')";

string SqlQuery = "SELECT Name FROM Table3 where Win Draw Lose Total ='" + Label15.Text + "'", '" + Label16.Text + "'", '" + Label17.Text + "'", '" + Label18.Text + "'";
   
string connectionstring = "Data Source=LENOVO-8962B730\\SQLEXPRESS;Initial Catalog=Michael;Integrated Security=True;Pooling=False";
  SqlConnection cn = new SqlConnection(connectionstring);
  SqlCommand cmd = new SqlCommand(SqlQuery, cn);
  try
  {
  cn.Open();
  SqlDataReader reader = cmd.ExecuteReader();
  DataTable DT = new DataTable();
  DT.Load(reader);
  int insertdata = DT.Rows.Count;
  cmd = new SqlCommand(Sql, cn);
  int DataUpdata;
  DataUpdata = cmd.ExecuteNonQuery();  
  }
  cn.Close();
  reader.Close();
  }
  catch (Exception)
  {
  }

------解决方案--------------------