I don’t know if it counts. Anyway, I write it for myself at any time. It’s very simple and suitable for collection by novices like me. Maybe it will come in handy!
One group is me who wrote the guestbook in the past two days, and the other group is
the experts who used to write polls in VS2003. If you see this, please tell me a good solution, thank you! ! If you are new, let’s learn together! !
--------The following is what I used to write a guestbook recently------------
public static OleDbConnection con()
{//Database connection class
OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings["book"].ConnectionString);
return con;
}
public static bool insert(string que)
{ //Perform the insert operation based on the passed in 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)
{//Return a data table loaded with SQL-defined 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 according to the passed conditions, and return true if so.
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)
{//It also returns the value of a field based on the passed SQL statement. I don’t like to put the SQL statement in it. It feels inflexible.
OleDbConnection con = odb.con();
con.Open();
OleDbCommand cmd = new OleDbCommand(que,con);
return cmd.ExecuteScalar().ToString();
}
-----------The following is what was used in 2003----------
public static SqlConnection con()
{//(Static) Initialization link, because the database path is in the web.config file, so which string is returned here, this is the initial instance of the database connection of VS2003
SqlConnection con=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["con"]);
return con;
}
public static bool chklog(string name,string pwd)
{//Determine whether 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 permissions of the current user and return 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 based on the passed SQL statement and fill 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) Return the title of the voting item based on the passed ID
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) execute 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) execute 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 generated ID, return whether the vote to which the ID belongs is a multi-choice or single-choice vote
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 type;
}
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)
{//Query any single field and return a static method of field value
SqlConnection con=db.con();
con.Open();
SqlCommand cmd=new SqlCommand(query,con);
return cmd.ExecuteScalar().ToString();
}
public static bool vlog(string query)
{//Query any single field, a static method that returns true or 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;
}
}
http://thcjp.cnblogs.com/archive/2006/06/18/428775.html