A column is selected, such as the user ID column
// user ID to be inserted
String ll_userID = "XXXXXXXX";
// inquiry number exist
SqlCommand mycmd = new SqlCommand ( "select a user ID from table where a user ID = '" + ll_userID + " '", mycon);
the SqlDataReader mysdr mycmd.ExecuteReader = ();
IF (mysdr.HasRows)
{
// this number has been recorded using
}
the else
{
// this number is not in use
}
mysdr.Close ();
mycon. the Close ();
---------- If the user ID column is an integer, then, can be written like this
int ll_userID;
// remove the current record number in the maximum value
SqlCommand mycmd = new SqlCommand ( "select max ( user number) from table ", mycon);
the SqlDataReader mysdr mycmd.ExecuteReader = ();
// detect whether there is also recorded the table is to determine whether the object is empty
iF (mysdr.HasRows)
{
// table is not empty, the maximum number +1 obtained on the basis of the query, and then insert a new record
}
the else
{
// table is empty, the default insert a minimum number of recording
}
mysdr.Close ();
mycon.Close ( );
C # with how to determine whether there is a value in the database
Guess you like
Origin www.cnblogs.com/sdxlz666/p/11029605.html
Recommended
Ranking