C#中执行SQL语句

C#中执行SQL语句
//SQL查询语句
  public DataTable query(string sql)
  {
   //server=127.0.0.1;
   DataTable dt=new DataTable();
   //DataRow dr;
   string connString = "server=127.0.0.1;uid=sa;pwd=;database=TJPTTC";
   SqlConnection conn = new SqlConnection(connString);
   SqlDataAdapter adapter = new SqlDataAdapter(sql,conn);
   adapter.Fill(dt);
   return dt;
  }
//SQL非查询语句
  public void noQuery(string sql)
  {
   //server=127.0.0.1;
   string connString = "server=GLASSESONION;uid=sa;pwd=;database=TJPTTC";
   SqlConnection conn = new SqlConnection(connString);
   SqlCommand cmd = new SqlCommand(sql,conn);
   conn.Open();
   cmd.ExecuteNonQuery();
   conn.Close(); 
  }

你可能感兴趣的:(C#,C,sharp,执行sql语句)