怎么将visual studio和数据库连接
2017-04-02
展开全部
1、在Web.config中配置
<connectionStrings>
<add name="数据库名称" connectionString="Data Source=(local); Initial Catalog=数据库名; Integrated Security=True; Persist Security Info=False"/>
</connectionStrings>
2、创建方法public static SqlConnection GetConnection()
{
string connectionString = ConfigurationManager.ConnectionStrings["数据库名称"].ConnectionString;
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
return connection;
}
3、通过SqlCommand执行
<connectionStrings>
<add name="数据库名称" connectionString="Data Source=(local); Initial Catalog=数据库名; Integrated Security=True; Persist Security Info=False"/>
</connectionStrings>
2、创建方法public static SqlConnection GetConnection()
{
string connectionString = ConfigurationManager.ConnectionStrings["数据库名称"].ConnectionString;
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
return connection;
}
3、通过SqlCommand执行
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询