SqlDataReader myReader = null;
    SqlConnection mySqlConnection = new SqlConnection("数据库连接");
    SqlCommand mySqlCommand = new SqlCommand("select * from customers", mySqlConnection);
    try
    {
      mySqlConnection.Open();
      myReader = mySqlCommand.ExecuteReader();
      while (myReader.Read())
      {
        Console.Write(myReader["CustomerID"].ToString() + "    ");
        Console.WriteLine(myReader["CompanyName"].ToString());
      }
    }
    catch(Exception e)
    {
      Console.WriteLine(e.ToString());
    }
    finally
    {
      if (myReader != null)
        myReader.Close();
      if (mySqlConnection.State == ConnectionState.Open)
        mySqlConnection.Close();
}
//操作这个对象
SqlConnection myConnection = new SqlConnection("server=(local)\NetSDK;Integrated Security=SSPI;database=northwind");
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter("select * from customers", myConnection);
mySqlDataAdapter.InsertCommand.CommandText = "sp_InsertCustomer";
mySqlDataAdapter.InsertCommand.CommandType = CommandType.StoredProcedure;
mySqlDataAdapter.Update(myDataSet);

mySqlDataAdapter->Update(myDataSet);

相关文章:

  • 2021-12-09
  • 2022-12-23
  • 2021-10-21
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-03-06
  • 2022-02-18
  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
相关资源
相似解决方案