server| Data | database
Simple and practical data reading, data manipulation methods, paste into the program directly call
Read method:
Public DataSet Query (string sqltext)
{
SqlConnection myconnection=new SqlConnection (configurationsettings.appsettings["Conn"));
DataSet ds = new DataSet ();
SqlDataAdapter mycommand = new SqlDataAdapter (sqltext,myconnection);
Mycommand.fill (DS);
return DS;
}
Action method:
Execute query, return SqlDataReader
Public SqlDataReader Querybyreader (string sqlstr)
{
if (sqlstr==string.empty)
return null;
SqlConnection myconnection = new SqlConnection (configurationsettings.appsettings["connstring"]);
SqlCommand mycommand = new SqlCommand (sqlstr, MyConnection);
Myconnection.open ();
SqlDataReader result = Mycommand.executereader (commandbehavior.closeconnection);
return result;
}
Manipulating the database without returning results
public bool Operatedb (string sqlstr)
{
if (sqlstr==string.empty)
return false;
SqlConnection myconnection = new SqlConnection (configurationsettings.appsettings["connstring"]);
SqlCommand mycommand = new SqlCommand (sqlstr, MyConnection);
Myconnection.open ();
Mycommand.executenonquery ();
Myconnection.close ();
return true;
}