2012-02-06 60 views
0

.hi大家对我有这样的代码:如何改变基于DataReader的结果VB文本框的选择选项

Private Sub EditPage_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
    'TODO: This line of code loads data into the 'InventorySysDataSet.tb_master_products' table. You can move, or remove it, as needed. 
    Me.Tb_master_productsTableAdapter.Fill(Me.InventorySysDataSet.tb_master_products) 
    sqlCnn = New SqlConnection("Data Source=ZEREY\SQLEXPRESS2008;Initial Catalog=InventorySys;Integrated Security=SSPI") 

    Me.txtRowId.Text = Form1.txtRowId.Text 
    'MsgBox(Me.txtRowId.Text) 
    sql = "Select * from tb_master_inventory_per_day where Inventory_Date = " & txtRowId.Text & "" 

    Dim upcmd As New SqlCommand("Select * from tb_master_inventory_per_day where Row_Id = @Row_Id", sqlCnn) 
    upcmd.Parameters.Add(New SqlParameter("@Row_Id", Me.txtRowId.Text)) 
    upcmd.Connection.Open() 
    Try 
     Dim dr As SqlDataReader = upcmd.ExecuteReader() 
     If dr.Read Then 
      txtInventoryDate.Text = dr.Item("Inventory_Date") 
      cboProductCode.DisplayMember = dr.Item("Product_Code") 
      txtQty.Text = dr.Item("Product_Count") 
     Else 
      MessageBox.Show("Error!") 
     End If 
    Catch ex As SqlException 
     If ex.Number <> 0 Then 
      'ErrorProvider1.SetError(Me.txtuseridprofile, "Login Id: " & 
      'Me.txtuseridprofile.Text & " :Not Found!") 
      upcmd.Connection.Close() 
      Exit Sub 
     End If 
    End Try 
    upcmd.Connection.Close() 


End Sub 

我想要做的是自动改变cboProductCode的选择的选项在页面加载取决于执行onload的查询的结果也是。 请帮助! TIA!

+0

我们在说客户端还是服务器端?也许你可以发表那些有查询的代码段,并告诉我们你想在哪里或什么时候更新DropDownList(它是我们正在谈论的DropDownList,不是吗?)。 – jhsowter 2012-02-06 22:59:49

+0

。它是一个下拉列表。 – zerey 2012-02-06 23:00:50

回答

0

。哈哈!有趣的是,我尝试了很多方法,但没有尝试使用cboProductCode.Text而不是cboProductCode.DisplayMember。它现在工作! :D

相关问题