How ASP. NET writes registration information to Access

Source: Internet
Author: User

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)

{

 

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.