使用Windows實現資料繫結----------的解析

來源:互聯網
上載者:User

標籤:建立   name   mes   tables   for   update   .sh   upd   new   


一.綁定下拉框資料

string sql = "select * from Grade";
SqlDataAdapter sda = new SqlDataAdapter(sql,helper.Con);
sda.Fill(ds,"Grade");
//建立一個下拉框選項
DataRow row = this.ds.Tables["Grade"].NewRow();
row[0] = -1;
row[1] = "請選擇";
this.ds.Tables["Grade"].Rows.InsertAt(row,0);

//綁定下拉框
this.cbograde.DataSource=ds.Tables["Grade"];
this.cbograde.DisplayMember="GradeName";
this.cbograde.ValueMember="GradeId";

 

二.綁定DataGradeView資料

//根據年級查詢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");
//綁定資料來源和DataGradeView
this.dgvStudent.DataSource = ds.Tables["Student"];
}
catch (Exception x)
{
MessageBox.Show(x.Message);
}

三.實現資料更新

DialogResult result=MessageBox.Show("確定更改資訊嗎?","提示",MessageBoxButtons.YesNo,MessageBoxIcon.Information);
if (result == DialogResult.Yes) {
SqlCommandBuilder scb = new SqlCommandBuilder(studentsda);
studentsda.Update(ds, "Student");
}

使用Windows實現資料繫結----------的解析

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.