WEB开发网
开发学院软件开发C语言 C#ADO.NET操作数据代码汇总 阅读

C#ADO.NET操作数据代码汇总

 2009-05-04 08:27:29 来源:WEB开发网   
核心提示: ②初始化具有查询文本的 SqlCommand 类的新实例,public SqlCommand(string);String mySelectQuery = "SELECT * FROM mindata";SqlCommand myCommand = new SqlCom

②初始化具有查询文本的 SqlCommand 类的新实例。public SqlCommand(string);

String mySelectQuery = "SELECT * FROM mindata";

SqlCommand myCommand = new SqlCommand(mySelectQuery);

③初始化具有查询文本和 SqlConnection 的SqlCommand类实例。

Public SqlCommand(string, SqlConnection);

String mySelectQuery = "SELECT * FROM mindata";

string myConnectString = "user id=sa;password=;database=test;server=mySQLServer";

SqlConnection myConnection = new SqlConnection(myConnectString);

SqlCommand myCommand = new SqlCommand(mySelectQuery,myConnection);

④初始化具有查询文本、SqlConnection 和 Transaction 的 SqlCommand 类实例。

public SqlCommand(string, SqlConnection, SqlTransaction);

SqlTransaction myTrans = myConnection.BeginTransaction();

String mySelectQuery = "SELECT * FROM mindata";

string myConnectString = "user id=sa;password=;database=test;server=mySQLServer";

SqlConnection myConnection = new SqlConnection(myConnectString);

SqlCommand myCommand = new SqlCommand(mySelectQuery,myConnection, myTrans);

2.建立SqlCommand与SqlConnection的关联。

myCommand.Connection = myConnection;

或者:SqlCommand myCommand = myConnection.CreateCommand;

3.设置SqlCommand的查询文本。

myCommand.CommandText = "SELECT * FROM mindata";

或者第2种构造:SqlCommand myCommand = new SqlCommand(mySelectQuery);

上一页  1 2 3 4 5 6  下一页

Tags:ADO NET 操作

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接