Asp. NET tip: Some common data manipulation classes

Source: Internet
Author: User
Tags bool count insert query tostring
Asp.net| Skills | data

I do not know calculate, anyway, I write at any time with, very superficial, suitable for the same as I the Novice collection, refers to the use of it!

One group is my two days to write a message, the other group is the previous VS2003 write a vote

Master See words, trouble put a good solution, thank you!! Novice words, learn together!!

--------The following is the------------I wrote a message this week.
public static OleDbConnection con ()
{//Database connection class
OleDbConnection con = new OleDbConnection (configurationmanager.connectionstrings["book"). ConnectionString);
return con;
}
public static bool Insert (string que)
{//Insert operation based on incoming SQL statement
OleDbConnection con = Odb.con ();
Con. Open ();
OleDbCommand cmd = new OleDbCommand (Que,con);
int count = Convert.ToInt32 (cmd. ExecuteNonQuery ());
if (Count > 0)
return true;
Else
return false;
Con. Close ();
}
public static DataTable DS (string que)
{//Returns a data table loaded with SQL-made messages,
OleDbConnection con = Odb.con ();
OleDbDataAdapter ODA = new OleDbDataAdapter ();
Oda. Selectcommand=new OleDbCommand (Que,con);
DataSet ds = new DataSet ();
Oda. Fill (ds, "THC");
Return DS. tables["THC"];
Con. Close ();
}
public static bool img (string que)
{////Check whether the item has content based on the conditions coming, return true
OleDbConnection con = Odb.con ();
Con. Open ();
OleDbCommand cmd = new OleDbCommand (Que,con);
if (cmd. ExecuteScalar (). ToString ()!= "")
return true;
Else
return false;
Con. Close ();
}
public static string SCR (string que)
{//is also based on the return of the SQL statement of the value of a field, I do not like to do the SQL statement, do not feel flexible
OleDbConnection con = Odb.con ();
Con. Open ();
OleDbCommand cmd = new OleDbCommand (Que,con);
return CMD. ExecuteScalar (). ToString ();
}

-----------The following is used in the past 2003----------
public static SqlConnection con ()
{//(static) initialize the link because the database path is inside the web.config file, so which string is returned here, which is the initial instance of the VS2003 database connection
SqlConnection con=new SqlConnection (system.configuration.configurationsettings.appsettings["con");
return con;
}
public static bool Chklog (String name,string pwd)
{//Determine if this user exists in the database, return TRUE or False
SqlConnection Con=db.con ();
Con. Open ();
SqlCommand cmd=new SqlCommand ("SELECT count (*) from admin where Name= ' +name+" ' and pwd= ' "+pwd+ '", con);
int Count=convert.toint32 (cmd. ExecuteScalar ());
if (count>0)
{
return true;
}
Else
{
return false;
}
}
public static string Chkqx (String name,string pwd)
{//Determine the current user's permissions and return permissions
SqlConnection Con=db.con ();
Con. Open ();
SqlCommand cmd=new SqlCommand ("Select qx from admin where Name= '" +name+ "' and pwd= '" +pwd+ "", con);
String qx=convert.tostring (cmd. ExecuteScalar ());
return QX;
}
public static DataTable Fill (string query)
{///query the data from the SQL statement and populate a table for the query object
SqlConnection Con=db.con ();
SqlDataAdapter Sda=new SqlDataAdapter ();
Sda. Selectcommand=new SqlCommand (Query,con);
DataSet ds=new DataSet ();
Sda. Fill (ds, "vote");
Return DS. tables["vote"];

}
public static string title (int ID)
{//(static) returns the title of the voting item based on the ID coming
SqlConnection Con=db.con ();
Con. Open ();
SqlCommand cmd=new SqlCommand ("Select Xiang from votemaster where id=" "+id+" ", con);
return CMD. ExecuteScalar (). ToString ();
}
public static void Delete (string query)
{//(static) performs the specified deletion behavior
SqlConnection Con=db.con ();
Con. Open ();
SqlCommand cmd=new SqlCommand (Query,con);
Cmd. ExecuteNonQuery ();
}
public static void Update (string query)
{//(static) performs the specified update behavior
SqlConnection Con=db.con ();
Con. Open ();
SqlCommand cmd=new SqlCommand (Query,con);
Cmd. ExecuteNonQuery ();
}
public static int cid (string query)
{//(static) query the latest ID of the current database based on the executed statement
SqlConnection Con=db.con ();
Con. Open ();
SqlCommand cmd=new SqlCommand (Query,con);
int Id=convert.toint32 (cmd. ExecuteScalar ());
return ID;
}
public static bool Insert (string query)
{//insert operation
SqlConnection Con=db.con ();
Con. Open ();
SqlCommand cmd=new SqlCommand (Query,con);
int Count=convert.toint32 (cmd. ExecuteNonQuery ());
if (count>0)
{
return true;
}
Else
{
return false;
}
}
public static int typ (int id)
{///according to the Out ID, return the vote of the ID belongs to the multiple or the radio
SqlConnection Con=db.con ();
Con. Open ();
SqlCommand cmd=new SqlCommand ("Select Typ from Votemaster where id=" "+id+" ", con);
int Typ=convert.toint32 (cmd. ExecuteScalar ());
return Typ;
}
public static string count ()
{//Return total number of visitors
SqlConnection Con=db.con ();
Con. Open ();
SqlCommand cmd=new SqlCommand ("Select Coun from Countline", con);
String Count=cmd. ExecuteScalar (). ToString ();
return count;
}
public static string Rengyi (string query)
{//query any Word field, return a static method
SqlConnection Con=db.con ();
Con. Open ();
SqlCommand cmd=new SqlCommand (Query,con);
return CMD. ExecuteScalar (). ToString ();
}
public static bool Vlog (string query)
{//query any Word field, return a static method of True and False
SqlConnection Con=db.con ();
Con. Open ();
SqlCommand cmd=new SqlCommand (Query,con);
int Count=convert.toint32 (cmd. ExecuteScalar ());
if (count>0)
{
return true;
}
Else
{
return false;
}
}



Related Article

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.