111,129
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
namespace DataAdapterDemo
{
public class SQLAccess
{
private static SqlConnection conn = new SqlConnection(@"server=.\SQLExpress;database=AdapterDemo;Trusted_Connection=SSPI");
private SqlDataAdapter sda = new SqlDataAdapter();
private DataSet ds = null;
public DataSet getDataSet()
{
try
{
conn.Open();
SqlCommand selectCommand = new SqlCommand("select * from Demo", conn);
sda.SelectCommand = selectCommand;
sda.Fill(ds);
return ds;
}
catch
{
return null;
}
finally
{
conn.Close();
conn.Dispose();
sda.Dispose();
}
}
}
}