大概思路是
abc=select 姓名 from login 姓名='name'
rs.open abc,conn,1
if not rs.EOF then
有记录
else
无记录
end if
具体方法
asp.net中如何查询一条记录是否在一张表中如果存在就把信息返回给Grideview
如果不存在就返回给Lable1.Text="你查询的数据不存在!";if(这个括号里面应该怎么写?)//记录存在
{
SqlDataAdapter myda = new SqlDataAdapter("select * from post where postID like'" + TextBox1.Text + "'", myconn);
DataSet myds = new DataSet();
myda.Fill(myds, "table");
myconn.Close();
DataSet ds = myds;
GridView1.DataSource = ds;
GridView1.DataBind();
}
else//记录不存在
{
Lable1.Text="你查询的数据不存在!";
TextBox1.Text="";
}
解决方案 »
select count(*) from post where postID like'" + TextBox1.Text + " 判断一下 数据行数 就好啦
这个是常用的方法。ds.Tables[0].Rows.Count>0就是有数据,反之没有。
SqlDataAdapter myda = new SqlDataAdapter("select * from post where postID like'" + TextBox1.Text + "'", myconn);
DataSet myds = new DataSet();
myda.Fill(myds, "table");
myconn.Close();
DataSet ds = myds;
if(ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = ds;
GridView1.DataBind();
}
else//记录不存在
{
Lable1.Text="你查询的数据不存在!";
TextBox1.Text="";
}
select count(0) from table where ....返回结果为0就是没数据,否则有几行则返回数字。
string mySel="SELECT count(*) as iCount from gly where g_name='"+TextBox1.Text+"'";
SqlCommand myCmd1=new SqlCommand(mySel,myConn);
myCmd1.Connection.Open();
SqlDataReader Dr1=myCmd1.ExecuteReader();
Dr1.Read();
string Count=Dr1["iCount"].ToString();
Dr1.Close();
if(Count!="0")
{
//记录存在
}
else//记录不存在
{
Lable1.Text="你查询的数据不存在!";
TextBox1.Text="";
}
SqlDataAdapter myda = new SqlDataAdapter("select * from post where postID like'" + TextBox1.Text + "'", myconn);
DataSet myds = new DataSet();
myda.Fill(myds, "table");
myconn.Close();
if (myds.Tables[0].Rows == 0)
{
Lable1.Text="你查询的数据不存在!";
TextBox1.Text="";
}
else
{
GridView1.DataSource = myds;
GridView1.DataBind()
}
SqlDataAdapter myda = new SqlDataAdapter("select * from post where postID like'" + TextBox1.Text + "'", myconn);
DataSet myds = new DataSet();
myda.Fill(myds, "table");
myconn.Close(); if(myds.Tables[0].Rows.Count>0)//记录存在
{
GridView1.DataSource = myds;
GridView1.DataBind();
}
else//记录不存在
{
Lable1.Text="你查询的数据不存在!";
TextBox1.Text="";
}不要生成多余的DataSet,占资源的,你最好优化一下,用Datareader
《黎明杀机》开发商正开发新的《Serious Sam》游戏 由Devolver发行
超英派遣中心即将登陆Xbox Play Anywhere 深入了解这款独特而备受喜爱的冒险游戏
在《Hunter: The Reckoning – Deathwish》中怎么从猎物蜕变为猎手
《The Expanse: Osiris Reborn》——深入了解玩法 新同伴 封闭测试及发行窗口
Alien Deathstorm 科幻生存与动作结合 打造全新第一人称恐怖混合体验
宝可梦公司已在考虑未来可用口袋妖怪总数达到“或许一万只”
幸存者村庄2
怪可爱的店折相思菜单
怪可爱的店折相思菜单是一款画风治愈的模拟经营佳作,内置折相思菜单解锁多项便利功能
lol电竞经理人手游
lol电竞经理人手游让你可以成为职业的电竞经理人,在游戏中掌控游戏的走向!豪华阵
梦幻奶茶屋小游戏
梦幻奶茶屋是一款主打温馨治愈氛围的休闲经营作品,玩家将化身元气满满的奶茶店店长,
萌宠养成物语无限金币版
萌宠养成物语无限金币版是一款治愈系模拟养成游戏,以可爱卡通画风构建温馨虚拟世界,