如何将下拉框中的值添加到Mysql查询中?
我有一个下拉框,您可以在其中选择以下内容: 今天 最后7天 MySQL查询是:如何将下拉框中的值添加到Mysql查询中?,mysql,vb.net,Mysql,Vb.net,我有一个下拉框,您可以在其中选择以下内容: 今天 最后7天 MySQL查询是: Dim x1 As New MySqlConnection("Server=localhost;Database=test;UID=test;PWD=test;") x1.Open() Dim comx1 As New MySqlCommand("SELECT COUNT(*) as c FROM toutcome WHERE AffID = '" & CType(Session.Item("affID"),
Dim x1 As New MySqlConnection("Server=localhost;Database=test;UID=test;PWD=test;")
x1.Open()
Dim comx1 As New MySqlCommand("SELECT COUNT(*) as c FROM toutcome WHERE AffID = '" & CType(Session.Item("affID"), String) & "' AND CompletedDate= '" & DropDownList1.Text & "'", x1)
Dim myReaderx1 As MySqlDataReader = comx1.ExecuteReader(CommandBehavior.CloseConnection)
myReaderx1.Read()
Label12.Text = myReaderx1.Item(0).ToString()
dropbox中今天的值应为CURDATE
因此,查询应该如下所示:
Dim x1 As New MySqlConnection("Server=localhost;Database=test;UID=test;PWD=test;")
x1.Open()
Dim comx1 As New MySqlCommand("SELECT COUNT(*) as c FROM toutcome WHERE AffID = '" & CType(Session.Item("affID"), String) & "' AND CompletedDate = CURDATE() ", x1)
Dim myReaderx1 As MySqlDataReader = comx1.ExecuteReader(CommandBehavior.CloseConnection)
myReaderx1.Read()
Label12.Text = myReaderx1.Item(0).ToString()
我该怎么做?
将DropDownList 1.文本填入Dropbox中的值。到目前为止,已有2人编辑了该问题,但没有人尝试回答或帮助。如果你不能帮忙,请不要浪费我的时间。Stackoverflow也适合像我这样需要帮助和教育的人。
Dim commandText = "SELECT COUNT(*) as c FROM toutcome " & _
"WHERE AffID = '" & CType(Session.Item("affID"), String) & "' AND CompletedDate = @init "
Using c = New MySqlConnection("Server=localhost;Database=test;UID=test;PWD=test;")
Using com = New MySqlCommand(commandText, c)
c.Open()
com.Parameters.Add("@init", MySqlDbType.String).Value = Convert.ToString(DropDownList1.Text)
Using myReader = com.ExecuteReader(CommandBehavior.CloseConnection)
If myReader.Read() Then
Label11.Text = myReader.Item(0).ToString()
myReader.Close()
End If
End Using
End Using
End Using