Select a column, such as a user number column
User number to insert
String ll_userid= "xxxxxxxx";
Query whether this number exists
SqlCommand mycmd = new SqlCommand ("Select User number from table where user number = '" +ll_userid+ "'", mycon);
SqlDataReader MYSDR = myCMD. ExecuteReader ();
if (MYSDR. HasRows)
{
There are already records using this number
}
Else
{
This number is not being used
}
MYSDR. Close ();
Mycon. Close ();
----------If the user number column is an integer type, you can also write this
int Ll_userid;
Remove the maximum number value from the current record
SqlCommand mycmd = new SqlCommand ("Select max (user number) from table", mycon);
SqlDataReader MYSDR = myCMD. ExecuteReader ();
It also detects if a record is intended to determine if the table is empty
if (MYSDR. HasRows)
{
Table is not empty, based on the maximum number of queries obtained +1, and then insert a new record
}
Else
{
Table is empty, a default minimum number record is inserted
}
MYSDR. Close ();
Mycon. Close ();
How to tell if a value exists in a database in C #