最近在看《ADO.NET2.0高级程序设计》,看完给我一个豁然开朗的感觉,突然觉得理解了很多,以前迷迷糊糊的东西一下全都解开了,下面就关于连接与执行写点东西,这个方法应用到AE的话,我想不出一年我会将它弄熟。如果还又更好的写法的话,不妨各位网友也列上来!欢迎交流~~!
//=========ADO.NET的咬文嚼字======================
//四种连接方式
public void dataConClassfunction1()
{
///第一种连接方式
string SqlConnectionString = "Data Source=(local);Database=SQLDataTest;Integrated Security=SSPI;";
SqlConnection sqlcon = new SqlConnection();
sqlcon.ConnectionString = SqlConnectionString;
}
public void dataConClassfunction2()
{
///第二种连接方式
string SqlConnectionString = "Data Source=(local);Database=SQLDataTest;Integrated Security=SSPI;";
SqlConnection sqlcon = new SqlConnection(SqlConnectionString);
}
public void dataConClassfunction3()
{
///第三种连接方式
SqlConnection sqlcon = new SqlConnection("Data Source=(local);Database=SQLDataTest;Integrated Security=SSPI;");
}
public void dataConClassfunction4()
{
///第四种连接方式
SqlConnectionStringBuilder ConStringBuilder = new SqlConnectionStringBuilder();
ConStringBuilder.DataSource = "(local)";
ConStringBuilder.InitialCatalog="SQLDataTest";
ConStringBuilder.IntegratedSecurity=true;
SqlConnection sqlcon = new SqlConnection(ConStringBuilder.ToString());
}
//三种执行方式
public void dataCommandClassfunction1()
{
///第一种命令执行方式
SqlConnection SqlDataCon = new SqlConnection();
SqlCommand sqlCom = new SqlCommand();
sqlCom.Connection = SqlDataCon;
sqlCom.CommandType = CommandType.Text;
sqlCom.CommandText = "Select * From UserIdentiytable";
}
public void dataCommandClassfunction2()
{
///第二种命令执行方式
SqlConnection SqlDataCon = new SqlConnection();
SqlCommand sqlCom = new SqlCommand("Select * From UserIdentiytable",sqlcon);
}
public void dataCommandClassfunction3()
{
///第三种命令执行方式
SqlConnection SqlDataCon = new SqlConnection();
SqlCommand sqlCom = SqlDataCon.CreateCommand();
sqlCom.CommandType = CommandType.Text;
sqlCom.CommandText = "Select * From UserIdentiytable";
}