Read the data-bound grid from MySQL, and then bind the SQL

Source: Internet
Author: User

Get data inside MySQL protected void button1_click (object sender, EventArgs e) {///instantiate a strongly typed dataset macs_20140707tableadapter data = New Macs_20140707tableadapter (); DataTable ds= data. Getdatabyselect (); Gridview1.datasource = ds; Gridview1.databind (); } #region Insert SQL////// get all the data from the grid into the SQL database //////// protected void button2_click (object sender, EventArgs e) {string connectionString = "server=.; database=gz.sunnywifi.com;uid=sa;pwd=123456 "; SqlConnection conn = new SqlConnection (connectionString); try {Conn. Open (); for (int i = 0; i < GridView1.Rows.Count; i++) {String sqlstr = ""; SqlCommand comm = new SqlCommand (); String Router_mac = Gridview1.rows[i]. Cells[0]. Text.trim (). ToString (); String Device_mac = Gridview1.rows[i]. CELLS[1]. Text.trim (). ToString (); String create_time = Gridview1.rows[i]. CELLS[2]. Text.trim (). ToString (); int ID = Convert.ToInt32 ((gridview1.rows[i]. CELLS[3]. Text.trim (). ToString ())); String Ap_mac = Gridview1.rows[i]. CELLS[4]. Text.trim (). ToString (); int singal = Convert.ToInt32 ((gridview1.rows[i]. CELLS[5]. Text.trim (). ToString ())); Sqlstr + = "INSERT greenvpn_cm (addre_mac,dev_mav,greate_time,ap_mac,sunny_sinqh,ys_id) VALUES ('" + Router_mac + "', '" + D Evice_mac + "', '" + Create_time + "', '" + Ap_mac + "', '" + Singal + "', '" + ID + "');"; Comm.commandtext = sqLSTR; Comm. Connection = conn; Comm. ExecuteNonQuery (); }} catch (Exception ex) {Response.Write ("update failed, reason for failure:" + ex. Message); } finally {Conn. Close (); }} #endregion

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.