【问题标题】:datareader to read a data from database filter and show in textboxdatareader 从数据库过滤器中读取数据并显示在文本框中
【发布时间】:2011-04-28 03:52:22
【问题描述】:

嗨,朋友,我现在有一个带有一个组合框和文本框的表单另一方面我有一个 sql 数据库

将两列命名为余额,第一列作为客户名称,另一列作为 obbalance,我现在有了

将所有客户名称绑定到组合框现在我要做的是让用户选择一个

组合框中的客户名称文本框应显示所选对象的平衡

customername 你能帮我吗........请把代码发给我

【问题讨论】:

    标签: sql vb.net sqldatareader


    【解决方案1】:

    你的问题不是很清楚,但我会试一试。这假设您使用的是 SQL 数据库,并且客户名称在余额表中是唯一的。

    Using conn As New SqlConnection("YourConnectionString"), _
          command As New SqlCommand("SELECT obbalance from _
          balance where customername=@customername)
    
          command.parameters.add("@customername", SqlDbType.Char)
    
          command.parameters("@customername").value = "CustomerNameFromTextBox"
    
          Dim obbalance As Decimal = CDec(command.ExecuteScalar)
    
    End Using
    

    您需要将“YourConnectionString”替换为特定于您的数据库的真实连接字符串。将“CustomerNameFromTextBox”替换为在您的客户文本框中选择的名称。您可能还需要更改 obbalance 的数据类型和 @customername 参数以匹配数据库中的数据类型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-04
      • 2021-05-23
      • 1970-01-01
      • 2013-03-23
      • 1970-01-01
      • 2014-04-13
      相关资源
      最近更新 更多