我使用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子句吗?
答案 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);
}