我要做的是修改这段代码,这样我就可以获取第二个数据表来附加,如何附加第二个数据表的结果?
Dim myDataTable As New DataTable
Dim sqlConnection1 As New SqlConnection("connectionstring")
Dim cmd As New SqlCommand
Dim reader As SqlDataReader
Dim Family_id = lbFamilies.SelectedItem.Value
cmd.CommandText = "SELECT * FROM table WHERE Family_id=@Family_id"
cmd.Parameters.AddWithValue("@family_id", Family_id)
cmd.Connection = sqlConnection1
sqlConnection1.Open()
reader = cmd.ExecuteReader()
myDataTable.Load(reader)
sqlConnection1.Close()
lbProduct.DataSource = myDataTable
lbProduct.DataTextField = "product_name"
lbProduct.DataValueField = "product_id"
lbProduct.DataBind()
答案 0 :(得分:0)
假设两者具有相同的架构,请尝试此操作。
替换:
lbProduct.DataSource = myDataTable
lbProduct.DataTextField = "product_name"
lbProduct.DataValueField = "product_id"
lbProduct.DataBind()
有了这个:
CType(lbProduct.DataSource,DataTable).Merge(myDataTable);
lbProduct.DataBind();