首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C# 连接数据库的有关问题

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

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)
  {
  }

[解决办法]

热点排行