无法在页面加载上检索dropdownlist.selectedvalue?

时间:2012-02-04 15:54:41

标签: drop-down-menu count pageload

我有一个下拉框,它有从datasqlsource检索的值,但是我想在页面加载时得到计数值,但它似乎没有计算

'Dim adapter As New SqlDataAdapter
    'Dim ds As New DataSet


    'Dim connectionString = ConfigurationManager.ConnectionStrings("myProject").ConnectionString
    'Dim myConn As New SqlConnection(connectionString)

    'Dim cmd = "SELECT * FROM Group Where groupID='" & DropDownList1.SelectedValue & "' AND customerID='" & Session("customerID") & "'"






    'Try
    '    myConn5.Open()
    '    Dim myCmd5 As New SqlCommand(cmd5, myConn5)
    '    adapter.SelectCommand = myCmd5
    '    adapter.Fill(ds, "Group")
    '    ' txtQuan.Text = adapter.SelectCommand.ExecuteScalar().ToString()
    '    adapter.Dispose()
    '    myCmd5.Dispose()
    '    ' txtQuan.Text = ds.Tables(0).Rows.Count
    '    If ds.Tables(0).Rows.Count >= 10 Then
    '        lblNoPpl.Text = "The  group is full"
    '    Else
    '        Dim numLefts As Integer = 10 - ds.Tables(0).Rows.Count
    '        lblNoPpl.Text = numLefts.ToString() + "space left"



    'Catch ex As Exception
    '    MsgBox("Can not open connection ! ")
    'End Try

1 个答案:

答案 0 :(得分:0)

如果使用cmd.ExcuteScalar()方法检索计数,则sql应为

SELECT COUNT(*) FROM Group其中groupID ='“&amp; DropDownList1.SelectedValue&amp;”'AND customerID ='“&amp; Session(”customerID“)&amp;”'“< / p>