连c#接数据库的问题,求大神指教!
初学C#,好多都不懂,对着书写的,但是我运行不出,相应配置都改了
错误页没提示
namespace MySchool
{
class DBHelper
{
private static string conString = @"Data Source=YY;
AttachDbFilename=E:\c#教程\(MySchool)\DB\MySchool.mdf
Integrated Security=Ture;
Connect Timeout=30;
User Instance=True";
public static SqlConnection connection = new SqlConnection(conString);
}
}
public bool ValidateUser(string LoginType, string LoginId, string LoginPsw, ref string message)
{
int count = 0; //数据库查询结果
bool isValidUser = false; //返回值,是否找到该用户
//查询数据库,判断是否是合法用户
if (LoginType=="管理员") //验证管理员用户
{//使用sql语言查询数据库
string sql = string.Format("SELECT COUNT(*) FROM Admin WHERE LoginId='{0}' AND LoginPwd='{1}'", txtLoginId, txtLoginPwd);
try
{ //创建command对象
SqlCommand command = new SqlCommand(sql, DBHelper.connection);
DBHelper.connection.Open();//打开数据库连接
count = (int)command.ExecuteScalar();//执行查询语句
下断点显示运行到这里就走不下去了,有什么问题?
if (count==1)
&nb