您的位置:首页 > 数据库

两个数据库使用函数,比较简单

2008-07-16 14:23 393 查看
主要是没有用那些现成的东西,而且可以设置timeout时间

protected DataSet execString(string sqlString)
{
SqlConnection CDOSuiteConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["CDOSuiteConnectionString"].ConnectionString);
try
{
CDOSuiteConnection.Open();
SqlCommand sqlCmd = new SqlCommand(sqlString, CDOSuiteConnection);
sqlCmd.CommandType = System.Data.CommandType.Text;
sqlCmd.CommandTimeout = 7200;
SqlDataAdapter da = new SqlDataAdapter(sqlCmd);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
finally
{
if (CDOSuiteConnection != null)
{
CDOSuiteConnection.Close();
}
}
}
protected void execNonQuery(string sqlString)
{
SqlConnection CDOSuiteConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["CDOSuiteConnectionString"].ConnectionString);
try
{
CDOSuiteConnection.Open();
SqlCommand sqlCmd = new SqlCommand(sqlString, CDOSuiteConnection);
sqlCmd.CommandType = System.Data.CommandType.Text;
sqlCmd.CommandTimeout = 7200;
sqlCmd.ExecuteNonQuery();
}
finally
{
if (CDOSuiteConnection != null)
{
CDOSuiteConnection.Close();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: