Presumably the idea is
Abc=select name from login name = ' name '
Rs.Open abc,conn,1
If not Rs. EOF Then
Have records
Else
No record
End If
Specific methods
asp.net how to query whether a record is in a table if it exists, return the information to Grideview
If it does not exist, return to lable1.text= "The data you are querying does not exist!" "; if (how should this bracket be written?) )//Record exists
{
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//record does not exist
{
lable1.text= "You query the data does not exist!" ";
Textbox1.text= "";
}
Solutions»
Select COUNT (*) from post where PostID like ' + TextBox1.Text + ' to judge the number of rows of data.
This is a common method. Ds. Tables[0]. Rows.count>0 is the data, not the opposite.
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//record does not exist
{
lable1.text= "You query the data does not exist!" ";
Textbox1.text= "";
}
Select COUNT (0) from table where .... Returns a result of 0 or no data, or several rows that return a number.
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")
{
Record exists
}
else//record does not exist
{
lable1.text= "You query the data does not exist!" ";
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= "You query the data does not exist!" ";
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)//record exists
{
Gridview1.datasource = myds;
Gridview1.databind ();
}
else//record does not exist
{
lable1.text= "You query the data does not exist!" ";
Textbox1.text= "";
Do not generate redundant dataset, the resource, you'd better optimize it, with DataReader