Determine whether the database has the same data

Source: Internet
Author: User

It is often used to determine whether the database has the same data. Is there any other method besides select? I would like to ask you here!

Sample Code in (urladd. aspx. CS)

// Determine whether the website exists

If (navigation. beurl (URL ))
{
Sperror. innertext = "you already have a database! ";
Return;
}

Query whether the website has a database

Public static bool beurl (string URL)
{
String SQL = "select count (1) from [navurl] Where [url] = @ URL ";
Sqlparameter parameters = new sqlparameter ("@ URL", sqldbtype. varchar, 50 );
Parameters. value = URL;
Return dbhelper. exists (SQL, parameters );

}

Dbhelper code

# Check whether the same data exists in the Region Query

Public static bool exists (string strsql)
{
Object OBJ = dbhelper. getsingle (strsql );
Int cmdresult;
If (object. Equals (OBJ, null) | (object. Equals (OBJ, system. dbnull. Value )))
{
Cmdresult = 0;
}
Else
{
Cmdresult = int. parse (obj. tostring ());
}
If (cmdresult = 0)
{
Return false;
}
Else
{
Return true;
}
}
Public static bool exists (string strsql, Params sqlparameter [] partition parms)
{
Object OBJ = dbhelper. getsingle (strsql, limit parms );
Int cmdresult;
If (object. Equals (OBJ, null) | (object. Equals (OBJ, system. dbnull. Value )))
{
Cmdresult = 0;
}
Else
{
Cmdresult = int. parse (obj. tostring ());
}
If (cmdresult = 0)
{
Return false;
}
Else
{
Return true;
}
}
# Endregion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.