Parsing----------using Windows to implement data binding

Source: Internet
Author: User


I. Binding the drop box data

String sql = "SELECT * from Grade";
SqlDataAdapter SDA = new SqlDataAdapter (Sql,helper. Con);
Sda. Fill (ds, "Grade");
Create a new drop-down box option
DataRow row = this.ds.tables["Grade"]. NewRow ();
Row[0] =-1;
ROW[1] = "Please select";
this.ds.tables["Grade"]. Rows.insertat (row,0);

Tied Down Frame
This.cbograde.datasource=ds. tables["Grade"];
This.cbograde.displaymember= "Gradename";
This.cbograde.valuemember= "Gradeid";

Two. Binding Datagradeview data

Search by Grade Gradeid
String sql = "SELECT * from Student where gradeid= '" + this.cbograde.SelectedValue + "'";
Try
{
STUDENTSDA = new SqlDataAdapter (SQL, Helper. Con);

if (ds. tables["Student"]! = null) {
Ds. tables["Student"]. Clear ();
}
Studentsda. Fill (ds, "Student");
Binding data sources and Datagradeview
This.dgvStudent.DataSource = ds. tables["Student"];
}
catch (Exception x)
{
MessageBox.Show (X.message);
}

Three. Implementing Data Updates

DialogResult result=messagebox.show ("OK to change information?") "," hint ", messageboxbuttons.yesno,messageboxicon.information);
if (result = = Dialogresult.yes) {
SqlCommandBuilder SCB = new SqlCommandBuilder (STUDENTSDA);
Studentsda. Update (ds, "Student");
}

Parsing----------using Windows to implement data binding

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.