我有一个asp.net Web表单应用程序将数据绑定(REFERENCE_NO)到DropDownList(ddlRef).ddlRef根据BasicDatePickerControl(bdpApps)中的选定日期从MySql数据库中检索数据。我的代码如下:
Protected Sub loadRefnumbers()
Try
cmd = New MySqlCommand("select idapp,REFERENCE_NO from ONLINELOANS where APPLICATION_DATE ='" & DateFormat.getSaveDate(bdpApps.SelectedDate) & "'", con)
adp = New MySqlDataAdapter(cmd)
Dim ds As New DataSet
ds.Clear()
adp.Fill(ds, "DATE_REFS")
If ds.Tables(0).Rows.Count > 0 Then
ddlRef.DataSource = cmd.ExecuteReader()
ddlRef.DataTextField = "REFERENCE_NO"
ddlRef.DataValueField = "idapp"
ddlRef.DataBind()
Else
ddlRef.DataSource = Nothing
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
我有一个getSaveDate函数,它将basicdatepicker控件中的日期格式转换为MySql Date格式(YYYY-MM-DD)。当我调试应用程序时,ddlRef控件未更新以反映REFERENCE_NO列中的值。我的SQL命令有什么问题吗?
答案 0 :(得分:0)
上述问题的解决方案。对于那些在asp.net webforms中使用BasicDatePicker 1_4_3的人,我的问题的代码是在SelectionChanged处理程序上调用datepicker控件的查询:
Protected Sub bdpApps_SelectionChanged(sender As Object, e As EventArgs) Handles bdpApps.SelectionChanged
con = New SqlConnection(ConfigurationManager.ConnectionStrings("constr").ConnectionString)
Using cmd As New SqlCommand("SELECT id,REFERENCE_NO from ONLINELOANS where APP_DATE='" & DateFormat.getSaveDate(bdpApps.SelectedDate) & "'")
cmd.CommandType = CommandType.Text
cmd.Connection = con
con.Open()
ddlRef.DataSource = cmd.ExecuteReader()
ddlRef.DataTextField = "REFERENCE_NO"
ddlRef.DataValueField = "idapp"
ddlRef.DataBind()
ddlRef.Items.Insert(0, New ListItem("--SELECT--", "0"))
ddlRef.SelectedIndex = 0
con.Close()
End Using
End Sub