求一个asp.net连接数据库SQL SERVER的测试代码
本人asp.net新手,用的是visualstudio2008和sql2008数据库,求一个visualstudio2008连接sql2008数据库的测试代码,不要网站程...
本人asp.net新手,用的是visual studio2008和sql 2008数据库,求一个visual studio 2008连接sql 2008数据库的测试代码,不要网站程序,只要一个链接测试代码,谢谢了。这是我的邮箱 961147973@qq.com
展开
3个回答
展开全部
----web.config文件中的连接串
<connectionStrings>
<add name="SqlCon" connectionString="Server=localhost;DataBase=BookStore;User ID=sa;Pwd="
providerName="System.Data.SqlClient"/>
</connectionStrings>
连接串的测试
SqlConnection mycon = new SqlConnection();
mycon.ConnectionString = ConfigurationManager.ConnectionStrings["SqlCon"].ToString();
mycon.Open();
Label1.Text = mycon.State.ToString();
mycon.Close();
<connectionStrings>
<add name="SqlCon" connectionString="Server=localhost;DataBase=BookStore;User ID=sa;Pwd="
providerName="System.Data.SqlClient"/>
</connectionStrings>
连接串的测试
SqlConnection mycon = new SqlConnection();
mycon.ConnectionString = ConfigurationManager.ConnectionStrings["SqlCon"].ToString();
mycon.Open();
Label1.Text = mycon.State.ToString();
mycon.Close();
展开全部
----web.config文件中的连接串
<connectionStrings>
<add
name="SqlCon"
connectionString="Server=localhost;DataBase=BookStore;User
ID=sa;Pwd="
providerName="System.Data.SqlClient"/>
</connectionStrings>
连接串的测试
SqlConnection
mycon
=
new
SqlConnection();
mycon.ConnectionString
=
ConfigurationManager.ConnectionStrings["SqlCon"].ToString();
mycon.Open();
Label1.Text
=
mycon.State.ToString();
mycon.Close();
<connectionStrings>
<add
name="SqlCon"
connectionString="Server=localhost;DataBase=BookStore;User
ID=sa;Pwd="
providerName="System.Data.SqlClient"/>
</connectionStrings>
连接串的测试
SqlConnection
mycon
=
new
SqlConnection();
mycon.ConnectionString
=
ConfigurationManager.ConnectionStrings["SqlCon"].ToString();
mycon.Open();
Label1.Text
=
mycon.State.ToString();
mycon.Close();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询