string userpossword;
SqlConnection conn = new SqlConnection("server=.\\SQL2005;uid=sa;pwd=sa;database=TongXunLuDB");
string strcon = "select userpassword from UserLoginInfo where username='admin'";
conn.Open();
SqlCommand cmd = new SqlCommand(strcon,conn);
SqlDataReader dr = cmd.ExecuteReader() ;
userpossword = dr["userpassword"].ToString();
return userpossword;这是连接的函数,连接应该没又问题,就是datareader变量中没有值,在查询分析器中执行上面的SQL语句可以查出来结果,但是到这就没有结果,dr里面的字段没又问题,这到底为什么呢,这么简单的地方,,,
SqlConnection conn = new SqlConnection("server=.\\SQL2005;uid=sa;pwd=sa;database=TongXunLuDB");
string strcon = "select userpassword from UserLoginInfo where username='admin'";
conn.Open();
SqlCommand cmd = new SqlCommand(strcon,conn);
SqlDataReader dr = cmd.ExecuteReader() ;
userpossword = dr["userpassword"].ToString();
return userpossword;这是连接的函数,连接应该没又问题,就是datareader变量中没有值,在查询分析器中执行上面的SQL语句可以查出来结果,但是到这就没有结果,dr里面的字段没又问题,这到底为什么呢,这么简单的地方,,,
if(dr.Read())
{
userpossword = dr["userpassword"].ToString();
}
return userpossword;