Commonly used data operation classes

xiaoxiao2021-04-04  238

I don't know if it is not calculated. Anyway, I will write it at any time, very shallow, suitable for my newcomer collection, I don't use it!

A group is my two days to write a message (thank you first controlled reminder, about cleaning up, I will correct it again)

The other group is the previous VS2003 write vote

If you see it, please tell us a good solution, thank you! ! If you have a newcomer, learn together! !

------------

Below is my recent write message

----------------

public

Static

OLEDBCONNECTION CON ()

{// Database Connection Class OLEDBConnection Con = New OLEDBConnection (ConfigurationManager.Connectionstrings "; RETURN CON;}

public

Static

Bool

INSERT

String

QUE)

{// Perform insert operation oledbconnection con = ODB.CON () according to the source of SQL statement; con-oden (); oledbcommand cmd = new oledbcommand (que, con); int count = convert.Toint32 (cmd.executenon query () ); If (count> 0) Return True; Else Return False;}

public

Static

DataTable DS

String

QUE)

{// Returns a data sheet loaded with SQL, 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"];

public

Static

Bool

IMG

String

QUE)

{// Inquiry if the item is content, there is a content, there is a TRUE OLEDBCONNECTION CON = ODB.con (); con.open (); OLEDBCOMMAND CMD = New OLEDBCOMMAND (Que, Con); if (cmd.executescala () .Tostring ()! = "") Return True; else returnaf false;}

public

Static

String

SCR

String

QUE)

{// also returns a field according to the SQL statement from the SQL statement, I don't like to do the SQL statement, I feel unfamiliar oledbconnection con = ODB.CON (); con.open (); OLEDBCOMMAND CMD = NEW OLEDBCOMMAND (Que, Con); Return cmd.executescalar (). Tostring ();} -----------

Here is the previous 2003

------------

public

Static

SqlConnection Con ()

{// (static) initial link, because the database path is in the web.config file, so which string is returned here, this is the VS2003 database connection initial instance SQLConnection Con = New SqlConnection (System.configuration.configurationSettings.AppSettings [ "con"]); return con;

public

Static

Bool

Chklog

String

Name,

String

PWD)

{// Determine if this user is present in the database, return true or false sqlconnection con = db.con (); con. (); sqlcommand cmd = new sqlcommand ("SELECT Count (*) from admin where name = ' Name "'and PWD ='" PWD "'", "INT Count = Convert.Toint32 (cmd.executescalar ()); if (count> 0) {return true;} else {return false;}}}

public

Static

String

CHKQX

String

Name,

String

PWD)

{// judge the current user's permissions and return to the 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 according to the SQL statement and populate a table to 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 voting item title SqlConnection con = db.connection according to the ID (); con. (); sqlcommand cmd = new sqlcommand ("SELECT XIANG from votemaster where id = ' id " '", con); RETURN CMD.Executescalar (). Tostring ();

public

Static

Void

DELETE

String

Query

{// (static) Execute the specified delete behavior sqlConnection con = db.con (); con. ipen (); sqlcommand cmd = new sqlcommand (query, con); cmd.executenonquery ();

public

Static

Void

Update

String

Query

{// (static) Execute the specified update behavior SqlConnection Con = db.con (); con. ipen (); sqlcommand cmd = new sqlcommand (query, con); cmd.executenonquery ();

public

Static

int

CID

String

Query

{// (static) According to the statement executed, query the latest ID SQLCONNECONNECONNECONNECONNECONNECONNECONNECONNECONNECONNECTION 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 SQLConnection Con = db.con (); con. (); 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 id, the vote belongs to the ID belongs to the number of multiple selection or radio SQLConnection con = db.con (); con -.open (); sqlcommand cmd = new SQLCOMMAND ("SELECT TYP from votemaster where id = '" ID "' ", con); int type = convert.toint32 (cmd.executescalar ()); return type

public

Static

String

count ()

{// Return total number of visitors SQLConnection con = db.con (); con. (); sqlcommand cmd = new SQLCOMMAND ("SELECT Coun from Countline", Con); string count = cmd.executescalar (). Tostring () Return Count;}

public

Static

String

RENGYI (

String

Query

{// query any single field, return a static method of a field value SQLConnection con = db.con (); con. (); sqlcommand cmd = new sqlcommand (query, con); return cmd.executescalar (). Tostring }

public

Static

Bool

VLOG

String

Query

{// Query any single field, return true and false a static method sqlconnection con = db.con (); con. (); sqlcommand cmd = new sqlcommand (query, con); int count = convert.toint32 (cmd) .Executescalar (); if (count> 0) {return true;} else {return false;}}

转载请注明原文地址:https://www.9cbs.com/read-131805.html

New Post(0)