Tutorials to .com

Tutorials to .com » Dotnet » Foundation » Some commonly used data manipulation classes

Some commonly used data manipulation classes

Print View , by: iSee ,Total views: 15 ,Word Count: 1077 ,Date: Tue, 25 Aug 2009 Time: 9:59 PM

Even do not know if it is not, anyway, I always write with, very shallow, suitable for the novice like me collection, Zhi Buding on the lingua franca of it!

A group is my another two days to write a message in this group is to vote before the VS2003 used to write

Master to see if the trouble to a good solution for referring to the next, thank you oh! ! Novice, the common learned! !

-------- The following is my recent write a message to this use ------------
public static OleDbConnection con ()
(/ / Database Connection Class
OleDbConnection con = new OleDbConnection (ConfigurationManager.ConnectionStrings [ "book"]. ConnectionString);
return con;
)
public static bool insert (string que)
(/ / According to incoming SQL statements perform an insert operation
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)
(/ / Return a load of SQL data to develop a message table,
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)
(/ / According to the terms came to the query whether there is content, there are returns 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)
(/ / The same is based on coming from a SQL statement returns the value of the field, I do not like to do, including SQL statements, the feeling of not flexible
OleDbConnection con = odb.con ();
con.Open ();
OleDbCommand cmd = new OleDbCommand (que, con);
return cmd.ExecuteScalar (). ToString ();
)

----------- The following are used when previous 2003 ----------
public static SqlConnection con ()
(/ / (Static) initialization link, because the database path in web.config file inside, so here is what the returned string, which is an instance of VS2003 the initial database connection
SqlConnection con = new SqlConnection (System.Configuration.ConfigurationSettings.AppSettings [ "con"]);
return con;
)
public static bool chklog (string name, string pwd)
(/ / Determine whether there is the user database, return true or the 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 privileges
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)
(/ / Based on coming out of SQL statement to query data and populate a table to 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) According to the coming return to the ballot item ID Title
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) the deletion of the specified behavior
SqlConnection con = db.con ();
con.Open ();
SqlCommand cmd = new SqlCommand (query, con);
cmd.ExecuteNonQuery ();
)
public static void update (string query)
(/ / (Static) behavior of the specified update
SqlConnection con = db.con ();
con.Open ();
SqlCommand cmd = new SqlCommand (query, con);
cmd.ExecuteNonQuery ();
)
public static int cid (string query)
(/ / (Static) of the Executive's statement to query a database, the latest one out of the current ID
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 operations
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)
(/ / Based out of ID, returns the ID belongs to vote belong to multiple-choice 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 the 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)
(/ / Look for any single field, return the field value is 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)
(/ / Look for any single field, return true and false in a static method
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;
)
)
http://thcjp.cnblogs.com/archive/2006/06/18/428775.html


.NET foundation Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.