I wrote a special article for you. Let's take a look at it. It shows that the data validity is not taken into account here. If you need it, add it yourself.
Using System;
Using System. Data;
Using System. Configuration;
Using System. Collections;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Web. UI. HtmlControls;
Using System. Data. OleDb; // The OleDb space to be referenced here
Public partial class Default4: System. Web. UI. Page
{
// Database connection string
Static string strCon = @ "provider = Microsoft. Jet. OLEDB.4.0; Data source = C: \ Documents and Settings \ Administrator \ Desktop \ db1.mdb ";
// Declare the object to connect to the data source and the object to operate on the data source
OleDbConnection con = new OleDbConnection (strCon );
OleDbCommand cmd = new OleDbCommand ();
// Click the button to add a record
Protected void button#click (object sender, EventArgs e)
{
String name = TextBox1.Text. Trim (); // name
String sex = TextBox2.Text. Trim (); // gender
String QQ = TextBox3.Text. Trim (); // QQ
String email = TextBox4.Text. Trim (); // Email
// SQL statement to insert records
String insertText = "insert into info (name, gender, QQ, email) values ('" + name + "', '" + sex + "', '"+ QQ +"', '"+ email + "')";
// Open the data source
Con. Open ();
// Set the data source of the operation object
Cmd. Connection = con;
// SQL statement to be executed
Cmd. CommandText = insertText;
// Perform the operation
Cmd. ExecuteNonQuery ();
// Close the data source
Con. Close ();
}
Protected void Page_Load (object sender, EventArgs e)
{
}
}