需要将where子句添加到表适配器

时间:2012-02-28 19:30:07

标签: sql vb.net ado.net dataset tableadapter

我使用Visual Studio向导设置了数据集,并且在表单中是这行代码:

Me.StudentsTableAdapter.Fill(Me.StudentsDataSet.Students)

表适配器的select语句是:

SELECT ID, Forename, Surname, AddressLine1, AddressLine2, City, State, PostCode, 
       PrimaryPhone, SecondaryPhone, DateOfBirth, email, Grade, GPA, ParentID 
  FROM Students

你能告诉我如何在这个表适配器上使用编码添加Where子句吗?

2 个答案:

答案 0 :(得分:2)

您可以尝试使用SQLCommand对象,如下所示:

Dim cmd As New SqlCommand("SELECT * FROM Students WHERE ID=@ID", myConnection)
cmd.Parameters.AddWithValue("@ID", 5)
Me.StudentsTableAdapter.SelectCommand = cmd
Me.StudentsTableAdapter.Fill(Me.StudentsDataSet.Students)

答案 1 :(得分:0)

这是我在大学项目中的代码。

query = SELECT icode, category, iname, weight, price, pic, qty FROM   dbo.item_entry where(iname=@iname)

代码:

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e){
    this.item_entryTableAdapter.FillByItem(this.jewllary_DatabaseDataSet.item_entry, comboBox2.Text);
}