2014年7月13日 星期日

[RESOLVED] calculation as per dropdownlist value


 Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged, DropDownList1.TextChanged
Dim connectString1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\web\AUTH.mdb"
Dim con1 As OleDbConnection = New OleDbConnection(connectString1)
con1.Open()
Dim qstra As String
qstra = "select count(aco)from AUTH where company= DropDownList1.SelectedValue"
Dim OleDba As New OleDbDataAdapter(qstra, con1)
Dim dta As New DataSet
dta.Clear()
OleDba.Fill(dta, "AUTH")
lbl1.Text = dtA.Tables("AUTH").Rows(0).Item(0)
End Sub


Just change this line,


FROM:


qstra = "select count(aco)from AUTH where company= DropDownList1.SelectedValue"

TO: 


qstra = "select count(aco) from AUTH where company = '" & DropDownList1.SelectedValue & "'" 


i tried the code now the error which i got is removed and shows a numder but it is not the correct number which pertaining to that company


i want the number from field ACO of auth table for the compant which is selected in my dropdownlist



your query only return the number of rows. not the number from field ACO.



Simply remove the Count function from your SQL query. Just try the below one,


qstra = "select aco from AUTH where company = '" & DropDownList1.SelectedValue & "'" 

沒有留言:

張貼留言