C# windows编程SQL Server 2005 数据库连接
.net2.0 自带有个SQL Server 2005 ,请问在windows编程中怎么连接!
问题简单,谢谢赐教!
切记:不是web编程连接数据库!
------解决方案--------------------string afile = "server=IP; uid=sa ;pwd=as;database=数据库名 ";
SqlConnection acstr = new SqlConnection(afile);
acstr.Open();//打开数据库连接
string usname = "select chinesename from users where username= ' " + textBox1.Text + " ' and password= ' " + textBox2.Text + " ' ";//SQL语句
SqlCommand cmdd = new SqlCommand(usname, acstr);
SqlDataReader myreader = cmdd.ExecuteReader();
if (myreader.Read())
{
//执行成功
}
else
{
//执行失败
}
myreader.Close();
acstr.Close();
绝对可行·我测试过