-1
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    If Not IsPostBack Then
        TextBox3.Text = Now()
        Dim com As New SqlCommand
        com.CommandType = CommandType.Text
        com.CommandText = "select  productname ,productid,productdescreption,price from products order by productname "
        com.Connection = con
        Dim ad As New SqlDataAdapter

        Dim ds As New DataSet
        ad.SelectCommand = com
        ad.Fill(ds)

        DropDownList1.DataSource = ds
        DropDownList1.DataTextField = "productname"

        DropDownList1.DataValueField = "productid"
        'Dim ss As Integer
        'ss = Convert.ToInt32(DropDownList1.DataValueField)
        'DropDownList1.DataValueField = ss

        DropDownList1.DataBind()


        Dim com2 As New SqlCommand
        com2.CommandType = CommandType.Text
        com2.CommandText = "select  dealername ,dealerid from dealerin order by dealername  "
        com2.Connection = con
        Dim ad2 As New SqlDataAdapter

        Dim ds2 As New DataSet
        ad2.SelectCommand = com2
        ad2.Fill(ds2)

        DropDownList2.DataSource = ds2
        DropDownList2.DataTextField = "dealername"
        DropDownList2.DataValueField = "dealerid"
        DropDownList2.DataBind()



        'Dim com3 As New SqlCommand
        'com3.CommandType = CommandType.Text
        'com3.CommandText = "select distinct productname ,productid,productdescreption from products "
        'com3.Connection = con
        'Dim ad3 As New SqlDataAdapter

        'Dim ds3 As New DataSet
        'ad2.SelectCommand = com3
        'ad2.Fill(ds3)

        'DropDownList3.DataSource = ds3
        'DropDownList3.DataTextField = "productdescreption"
        'DropDownList3.DataValueField = "productid"
        'DropDownList3.DataBind()

    End If


End Sub
Dim dss As New DataSet
Public Function getproduct_byid(ByVal productid As Integer) As DataSet
    Try
        Dim com3 As New SqlCommand
        com3.CommandType = CommandType.StoredProcedure
        com3.CommandText = "getproduct_byid"
        com3.Connection = con
        'com.Parameters.AddWithValue("@productid", productid)
        Dim adapter3 As New SqlDataAdapter(com3)

        adapter3.Fill(dss, "product")
        Return dss
    Catch ex As Exception
        Response.Write("error due to " & ex.Message)
    End Try

End Function

Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged
    Try

        getproduct_byid(DropDownList1.SelectedValue)
        If dss.Tables("product").Rows.Count = 1 Then

            TextBox5.Text = dss.Tables("product").Rows(0).Item("price")


        End If
    Catch ex As Exception
        Response.Write("error due to " & ex.Message)
    End Try
End Sub

Protected Sub TextBox5_TextChanged(sender As Object, e As EventArgs) Handles TextBox5.TextChanged
    Try
        Dim a As Double
        Dim b As Double
        a = TextBox4.Text
        b = TextBox5.Text
        TextBox6.Text = A * b
    Catch ex As Exception
        Response.Write("error due to " & ex.Message)
    End Try

End Sub
4

1 回答 1

0

可能是您的数据表包含超过 1 行..

改变这个

If dss.Tables("product").Rows.Count = 1 Then

If dss.Tables("product").Rows.Count > 0 Then
于 2013-08-28T00:49:24.317 回答