This example of this article for you to share the Ado.net Universal Database access classes for everyone to learn, the specific content as follows
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using System.Data;
Using System.Data.SqlClient; Namespace Test {public class DBHelper {public static string constring = ' Data source=.;i Nitial catalog=bankdb; User Id=sa;
password=123; ";
Methods to perform additions and deletions public static int Runnoquery (string cmdtext, CommandType cmdtype, params sqlparameter[] pars) {
SqlConnection con = new SqlConnection (constring); Con.
Open ();
SqlCommand cmd = new SqlCommand (Cmdtext, con);
Cmd.commandtype = Cmdtype; if (pars!= null && pars. Length > 0) {foreach (SqlParameter p in pars) {cmd.
Parameters.Add (P); int rows = cmd.
ExecuteNonQuery (); Con.
Close ();
return rows; //Execute Query (DataSet) method public static DataSet Runselect (String cmdtext, CommandType cmdtype, params sqlparameter[ ] Pars{SqlConnection con = new SqlConnection (constring);
SqlDataAdapter da = new SqlDataAdapter (Cmdtext, con);
Da.SelectCommand.CommandType = Cmdtype; if (pars!= null && pars. Length > 0) {foreach (SqlParameter p in pars) {da.
SELECTCOMMAND.PARAMETERS.ADD (P);
The DataSet ds = new DataSet (); Da.
Fill (DS);
return DS; //Execute query to get a value public static object Runonevalue (String cmdtext, CommandType cmdtype, params sqlparameter[] Pars
{SqlConnection con = new SqlConnection (constring); Con.
Open ();
SqlCommand cmd = new SqlCommand (Cmdtext, con);
Cmd.commandtype = Cmdtype; if (pars!= null && pars. Length > 0) {foreach (SqlParameter p in pars) {cmd.
Parameters.Add (P); } Object obj = cmd.
ExecuteScalar (); Con.
Close ();
return obj;
} }
}
The above is the entire content of this article, I hope to help you learn.