没有适合查询条件的记录时,DataReader.Read()返回的是false!
解决方案 »
- 有关ASP.NET 模板 问题
- 速急
- 高手过来,有项目做。
- 如何开发ASP.net程序?
- 请问我的网站在我的电脑无法访问,但是别人就可以访问,我只有重启路由才能用,这是为什么啊?!!
- 谁有用VB2003写的会员登陆系统和留言本(ASP.NET)?
- .NET中的神密武器
- --------关于NTFS格式在建设网站时候遇到的问题,顶着有分,建站高手请进--------
- VS.NET2003能不能编译.cs文件成.dll文件?如果可以怎么做?
- C#里面计算文件大小的方法是什么?
- asp.net做的Web Service client端(实现查询功能)client端的代码有问题,请各位高手进来帮我看看!
- 请问这个关于select的SQL语句怎么写?
if (myReader.HasRows)
while (myReader.Read())
Console.WriteLine("\t{0}\t{1}", myReader.GetInt32(0), myReader.GetString(1));
else
Console.WriteLine("No rows returned.");myReader.Close();
if(myDataReader.read())
{
...
}
else
{
...
}
//定义语句
string mySelectQuery = "SELECT * from COding_table where COdingid='" +TextBox_Account.Text+"' and COpsw='"+TextBox_Pass.Text+"'";
string myConnString="server=fjw;uid=fjwfjw;pwd=fjwfjw;database=BankOfZH"; //联结
SqlConnection myConnection = new SqlConnection(myConnString);
SqlCommand myCommand = new SqlCommand(mySelectQuery,myConnection);
myConnection.Open();
//定义DataReader
SqlDataReader myDataReader;
//赋与DataReader以结果
myDataReader=myCommand.ExecuteReader();
if (myDataReader.Read())
{
LB_ERROR.Text="不存在此用户或密码错误";
LB_ERROR.ForeColor=Color.Red;
}
else
{
Response.Redirect("index1.aspx");
}
//将DataReader与DataGrid进行捆绑
//show.DataSource=myDataReader;
//show.DataBind();
//关闭
myDataReader.Close();
myConnection.Close();
}
帐号是:textbox_account 密码是:textbox_pass我在里面不输入东西! 他就跳到index1.aspx
我输入了东西!他什么反应都没有!
不明白
不过问题是我不输入东西! read()才返回false!当我输入任何东西(包括错误的信息)的时候!他没反应~
不知道是不是我的sql语句有错误!
请指教一下! 谢谢~
else
...aaaa=mydr(0)
endif
if (myDataReader.HasRows){ Response.Redirect("index1.aspx");
}
else{
LB_ERROR.Text="不存在此用户或密码错误";
LB_ERROR.ForeColor=Color.Red;}
没记录时为false
同理
if (!myDataReader.Read()) //判断是否为空,为空则运行
问题依旧!
是什么回事呢?
sql语句有错吗?
你看看这片文章
<%@Page language="C#" Debug="True"%>
<%@Import Namespace="System.Data"%>
<%@Import Namespace="System.Data.SqlClient"%>
<HTML>
<HEAD>
<TITLE></TITLE>
<script language="C#" runat="server" >
SqlConnection MyConnection;
int rowIndex;
private void Login_Click(Object sender, EventArgs E) {
MyConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlDataAdapter myCommand = new SqlDataAdapter("SELECT * FROM usertable ORDER BY username ASC", MyConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "usertable");
DataView dv=new DataView(ds.Tables["usertable"],"","username",DataViewRowState.CurrentRows);
rowIndex = dv.Find(username.Text);
if (rowIndex == -1){
label1.Text = "不存在此用户!";
} else{
DataRowView dr;
dr=dv[rowIndex];
if (dr["password"].ToString() == password.Text){
Response.Redirect("index1.aspx");
}
else{
label1.Text = "口令错误!";
}
}
}
</script>
</head>
<body>
<form runat="server">
用户:<asp:textbox ID="username" runat="server"/><br/>
口令:<asp:textbox ID="password" runat="server"/>
<asp:button ID="submit" Text="提交" OnClick="Login_Click" runat="server"/>
<asp:label ID="label1" runat="server"></asp:label>
</form>
</body>
</html>
我的代码如下:private void Button_Login_Click(object sender, System.EventArgs e)
{
//Response.Redirect("index1.aspx");
int rowIndex;
//定义语句
string mySelectQuery = "SELECT * from COding_table order by COdingid asc";
string myConnString="server=(LOCAL);uid=fjwfjwfjw;pwd=fjwfjw;database=BankOfZH"; //联结
SqlConnection myConnection = new SqlConnection(myConnString);
SqlDataAdapter myCommand = new SqlDataAdapter(mySelectQuery, myConnection);
//DataSet
DataSet ds = new DataSet();
myCommand.Fill(ds,"COding_table");
DataView dv=new DataView(ds.Tables["COding_table"],"","COdingid",DataViewRowState.CurrentRows);
rowIndex = dv.Find(TextBox_Account.Text);
if (rowIndex == -1)
{
LB_ERROR.Text = "不存在此用户!";
} else
{
DataRowView dr;
dr=dv[rowIndex];
if (TextBox_Pass.Text.Equals(dr["COpsw"].ToString())) ///问题所在*************************
{
Response.Redirect("index1.aspx");
}
else
{
LB_ERROR.Text = dr["COpsw"].ToString();
}
}
}问题出现在if (TextBox_Pass.Text.Equals(dr["COpsw"].ToString())) 这个判断上!
无论是我改为if (textBox_Pass.Text==dr["COpse"].ToString())后他都是返回false!执行else下面的语句!后来我显示出那password!即使我输入的密码和显示的一样!他也只执行else下面的语句!不明白!我数据哭里的password字段是char 字长为10
请大家指点一下!
麻烦了!
if (dr.GetString("COpse")==(string)textBox_Pass.Text)
mycomm.commandtext="select ...."
myadp.fill(dt)
if dt.rows.count<=0 then
msgbox("NO record")
end if
只要count一下就可以了
select count(*) from table where ...
然后在程序里
int count = (int)YourCommand.ExecuteScalar();
直接判断count值就可以了
{
do you want to do;
}
else
return;