gpt4 book ai didi

mysql - DateTimePicker 选择日期之间的记录

转载 作者:行者123 更新时间:2023-11-29 00:10:48 27 4
gpt4 key购买 nike

我的问题是关于在 datetimepicker 中选择的两个日期之间使用 mysql 在 vb net 中搜索。我在很多论坛中搜索过它,但不幸的是没有运气

Dim dbdataset As New DataTable
Dim bsource As New BindingSource
Dim sda As New MySqlDataAdapter
Dim reader As MySqlDataReader
Try
mysqlconn.Open()
' MessageBox.Show("ok")
Dim query As String
query = "SELECT * FROM(patient) WHERE imerominia BETWEEN '" & DateTimePicker3.Text & "' AND '" & DateTimePicker4.Text & "' group BY imerominia"

command = New MySqlCommand(query, mysqlconn)
sda.SelectCommand = command
sda.Fill(dbdataset)
bsource.DataSource = dbdataset
DataGridView1.DataSource = bsource
sda.Update(dbdataset)
reader = command.ExecuteReader
While reader.Read
Dim imerominia As String = reader.GetString("imerominia")
Dim imerominia1 As String = reader.GetString("imerominia")
DateTimePicker3.Text = (imerominia)
DateTimePicker4.Text = (imerominia1)

End While
mysqlconn.Close()

Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
mysqlconn.Dispose()
End Try
End Sub

最佳答案

Dim dbdataset As New DataTable
Dim bsource As New BindingSource
Dim sda As New MySqlDataAdapter
Dim reader As MySqlDataReader
Try
mysqlconn.Open()
' MessageBox.Show("ok")
'Dim query As String
'query = "SELECT * FROM patient WHERE imerominia BETWEEN '" & DateTimePicker3.Text & "' AND '" & DateTimePicker4.Text & "' group BY imerominia"

MySqlCommand cmd = new MySqlCommand();

cmd.CommandText = "SELECT * FROM patient WHERE imerominia BETWEEN '" & @p_Date & "' AND '" & @p1_Date & "' group BY imerominia"
cmd.Parameters.Add ("@p_Date", SqlDbType.DateTime).Value = DateTimePicker3.Value;
cmd.Parameters.Add ("@p1_Date", SqlDbType.DateTime).Value = DateTimePicker4.Value;


sda.SelectCommand = cmd
sda.Fill(dbdataset)
bsource.DataSource = dbdataset
DataGridView1.DataSource = bsource
sda.Update(dbdataset)
reader = cmd.ExecuteReader

While reader.Read
Dim imerominia As String = reader.GetString("imerominia")
Dim imerominia1 As String = reader.GetString("imerominia")
DateTimePicker3.Text = (imerominia)
DateTimePicker4.Text = (imerominia1)

End While
mysqlconn.Close()

Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
mysqlconn.Dispose()
End Try
End Sub
不应使用

DateTimePicker3.Text,您可以使用 DateTimePicker3.Value.DateDateTimePicker.Value 是控件表示的日期时间。 DateTimePicker.Text 是控件如何根据 Format 属性向用户显示其日期

关于mysql - DateTimePicker 选择日期之间的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25194426/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com