请问VS2012自带的SQL如何使用?

2025-01-27 14:04:54
推荐回答(1个)
回答1:

using (SqlConnection cn = new SqlConnection())
{
//VS2012 自带的SQL为 localdb,连接字符串有一点点不一样,其他功能都一样操作
cn.ConnectionString = @"data source=(localdb)\v11.0;Initial Catalog=C:\DATA\APPLICATIONDATABASE.MDF;integrated security=True;connect timeout=120";
cn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandText = "select * from table";

SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}