I believe that ASP. NET controls are quite comfortable to use, but I still feel that the controls have many defects. First, the portability is not very good,CodeThis is the king. The following provides the ADO. Net code. You only need to add this file to the app_code of the website project and modify several values so that you can easily access your local database.
The ADO. Net code is as follows:
Using system;
Using system. Data;
Using system. configuration;
Using system. LINQ;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. htmlcontrols;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. xml. LINQ;
Using system. Data. sqlclient;
Namespace WB
{
//
// access data in the database
// important variables in this class have been specified
///
public class dataaccess
{
Public dataaccess ()
{
//
// Todo: add the constructor logic here
//
}
# Region defines public variables
Public static string SQL _con = "Data Source = FELVEN-PC // sqlexpress ; Initial catalog =BBS ; Integrated Security = true "; // connection string
Public static string userid = ""; // after a user logs on, the user's identity must be determined based on the user's ID. This field is set to record the user's login ID.
Public static string key = "";
Public static string date = "";
Public static string bdate = "";
Public static string edate = "";
Public static int result_flag = 0;
Public static int number = 0;
// The following is an example of getting a template page.
Public static string muser_id = "";
Public static string muser_name = "";
Public static string mdegree = "";
Public static string mdepartment = "";
// View Details
Public static int result_number = 0;
Public static int result_whole = 0;
Public static sqlconnection con = new sqlconnection (SQL _con );
/// <Summary>
/// Define the SQL statement to be executed
/// </Summary>
Public static string sqlcmd = ""; // defines the SQL statement to be executed
Public static sqlcommand mycommand;
Public static sqldataadapter SDA = new sqldataadapter ();
Public static dataset DS = new dataset ();
# Endregion
/// <Summary>
/// This method is used to execute the SQL statement assigned to sqlcmd.
/// </Summary>
Public static void sqldc ()
{
Con. Close ();
If (con. State = connectionstate. Closed)
Con. open ();
Mycommand = new sqlcommand (sqlcmd, con );
If (sqlcmd. substring (0, 1) = "S" | sqlcmd. substring (0, 1) = "S ")
SDA. selectcommand = mycommand;
Else if (sqlcmd. substring (0, 1) = "D" | sqlcmd. substring (0, 1) = "D ")
SDA. deletecommand = mycommand;
Else if (sqlcmd. substring (0, 1) = "U" | sqlcmd. substring (0, 1) = "U ")
SDA. updatecommand = mycommand;
Else
SDA. insertcommand = mycommand;
Mycommand. executenonquery ();
// Sqldatareader SDR = mycommand. executereader ();
If (sqlcmd. substring (0, 1) = "S" | sqlcmd. substring (0, 1) = "S ")
{
DS. Tables. Clear ();
SDA. Fill (DS );
}
}
}
}
The two above are highlighted. One is the address of your local database, which can be seen when you open SQL server2005. The other is your database name.
After the bucket is added, the bucket WB must be included in the CS file.
Using WB;
Dataaccess. sqlcmd= "Insert into whole (patient_id, doctor_id, doing_date, doing_state) values ('" + values () + "', '" + txtdoctor_id.text.trim () + "', '"+ time +"', 0 )";
Dataaccess. sqldc ();
Thank the boss for providing technical support.