2013-08-27 361 views
-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 
+3

你需要告訴你的觀衆在哪裏,什麼是問題。 – LarsTech

+0

這當然是一段代碼......當然,這有助於理解到底發生了什麼。例如,我計算了至少4個不同的文本框控件......提示哪個人有這個問題是至關重要的。當然,後續的問題是你是否試過單步執行代碼。 – NotMe

回答

0

這可能是你的數據表中包含超過1行..

更改此

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

If dss.Tables("product").Rows.Count > 0 Then