Implementation Code for ASP. NET Book information entry and asp.net book information entry

Source: Internet
Author: User

Implementation Code for ASP. NET Book information entry and asp.net book information entry

1. Create a test database and a book_info table in the test database.
Book_name varchar (100)
Author varchar (50)
Press varchar (50)
Press_date varchar (20)
Image varchar (30)

2. Create the following page:

When you click "insert book information", save your information to the book_info table. Note: The cover Image must be uploaded to the "upload" folder under the root directory of the website, and then saved to the Image field in the book_info table of the database.
Layout code:

<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default. aspx. cs" Inherits = "_ Default" %> <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN "" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <Html xmlns =" http://www.w3.org/1999/xhtml "> <Head runat =" server "> <title> 

Cs code

Using System; using System. collections. generic; using System. linq; using System. web; using System. web. UI; using System. web. UI. webControls; using System. data. sqlClient; public partial class _ Default: System. web. UI. page {protected void Page_Load (object sender, EventArgs e) {} protected void button#click (object sender, EventArgs e) {string savePath = Server. mapPath ("~ /Images/"); if (FileUpload1.HasFile) {String fileName = FileUpload1.FileName; savePath + = fileName; FileUpload1.SaveAs (savePath);} string SQL =" Data Source = A25; initial Catalog = test; Integrated Security = True "; string sqlStr = @" Insert into book_info (Book_name, Author, Press, Press_date, Image) values ('"+ TextBox1.Text + "', '"+ TextBox2.Text +"', '"+ DropDownList1.SelectedItem. text + "','" + Calend Ar1.SelectedDate. toShortDateString () + "','" + FileUpload1.FileName + "')"; using (SqlConnection conn = new SqlConnection (SQL) {conn. open (); using (SqlCommand cmd = conn. createCommand () {cmd. commandText = sqlStr; cmd. executeNonQuery () ;}} Response. write ("insert successful! ");}}

The above is all the content of this article. I hope it will inspire you and help you learn it.

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.