怎么将visual studio和数据库连接

2024-12-29 03:35:28
推荐回答(1个)
回答1:

1、在Web.config中配置



2、创建方法public static SqlConnection GetConnection()
{
string connectionString = ConfigurationManager.ConnectionStrings["数据库名称"].ConnectionString;
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
return connection;
}
3、通过SqlCommand执行