从你写的代码看来,是不是对SQL语句不想用呢?SqlConnection 为什么不用上???别的方法不说了。但从你的代码看来,
可能是string pw = row[0].ToString ();这个出错。因你的SQL语没指定第一列,ROW的返回是数据库中表中的第一列,你可以改改SQL语句为:
SqlDataAdapter myDataAdapter=new SqlDataAdapter("Select “这里明确第几行的字段是什么” from member",myConnection);
第二改法就是string pw = row["指明字段"].ToString ();
希望能帮到你~
可能是string pw = row[0].ToString ();这个出错。因你的SQL语没指定第一列,ROW的返回是数据库中表中的第一列,你可以改改SQL语句为:
SqlDataAdapter myDataAdapter=new SqlDataAdapter("Select “这里明确第几行的字段是什么” from member",myConnection);
第二改法就是string pw = row["指明字段"].ToString ();
希望能帮到你~
我的SqlConnection 本来就用到了亚,
修改的如下
String selectCmd="select Id from member where Id="+id.Text;
SqlConnection myConnection=new SqlConnection("Server=(local);Database=Com;Trusted_Connection=yes");
SqlDataAdapter myDataAdapter=new SqlDataAdapter("Select Psw from member",myConnection);
DataSet DS=new DataSet();
myDataAdapter.Fill(DS);
table =DS.Tables[0];
foreach (DataRow row in table.Rows)
{
string pw = row["Psw"].ToString ();
if (String.Compare (psw.Text, pw, false) == 0)
{ Response.Redirect("upload.aspx");
}
}
psw_message.Text="名称或密码错误,请重试";
}
}
别写错了,是说你的selectCmd没用到。如下的一些方法可以参考一: String sSQL ="SELECT count(*) as count1 FROM usertable WHERE name='" + 用户名变量 +"' AND psw='" + 用户输入的密码 + "'" ; //count(*) 为影响记录数的函数。
SqlCommand cm=new OleDbCommand(sSQL, SqlConnection);
SqlDataReader rd; //定义数据集
rd=cm.ExecuteReader(); //执行查询并返回数据
rd.Read()
if (0==Convert.ToInt16(rd["count1"]))
//没有找到记录。
else
//存存符合条件的记录。
--------
参考二
String sSQL ="SELECT * FROM usertable WHERE name='" + 用户名变量 +"' AND psw='" + 用户输入的密码 + "'" ; SqlCommand cm=new OleDbCommand(sSQL, SqlConnection);
SqlDataReader rd; //定义数据集
rd=cm.ExecuteReader(); //执行查询并返回数据
if (!rd.Read())
//没有找到记录。
else
//存存符合条件的记录。
---------------------------
改为:
SqlCommand cm=new SqlCommand (sSQL, SqlConnection);
祝你好运
我的解决方法是不用把sql语句改为select Id,Psw from member,再在foreach与句中这样写
:foreach (DataRow row in table.Rows)
{ string ida=row["id"].ToString();
string pwa = row["Psw"].ToString ();
if ((String.Compare (id.Text, pw, false) == 0)&&(String.Compare(psw.Text,pwa,false)==0))
{ Response.Redirect("upload.aspx");
}
}
psw_message.Text="名称或密码错误,请重试";
}