- 创建类SQLSERVER连接
- 呼叫连接类中使用的所有形式。
我想用C#在类中创建SQLServer连接以使用所有表单。在类文件连接如何使用c#在类中创建sqlconnection以用于所有表单?
溜码
public System.Data.SqlClient.SqlConnection Con = new System.Data.SqlClient.SqlConnection();
public System.Data.SqlClient.SqlCommand Com = new System.Data.SqlClient.SqlCommand();
public string conStr;
public SQL2(string conStr)
{
try
{
Con.ConnectionString = conStr;
Con.Open();
Com.Connection = Con;
Com.CommandTimeout = 3600;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public bool IsConnection()
{
Boolean st;
if (Con.State==ConnectionState.Open)
{
st=true;
}
else
{
st = false;
}
return st;
}
能给我完整的示例代码?
好的,请尝试再次解释它,并使用英语这次。你有什么问题? – walther 2012-04-29 14:08:34
在你完成任务后关闭你的连接。不要在这样的课堂上让他们打开。 – LarsTech 2012-04-29 14:10:36