仅随机搜索仅与显示数据相对应的日期
我的代码仅在星期六才寻找我,但随机它也会寻找我的表格中不存在的星期六,例如11月2日,星期六,我没有数据,我希望它跳过那些没有数据要显示的数据的日期在DataGridView中。因此,当随机对DatatimePichker进行随机化时,我希望它跳过那些与我的桌子中没有任何内容的日期或周六,然后将其移至下周六,直到找到与完整行匹配的日期,而不是null。 2 使用按钮,我创建了可能搜索2个DateTimePicker(1和2)的目标搜索,在这种情况下,仅在星期六,我在表中拥有的数据,并且我使用DataGridView显示。
我想要的是,在周六的随机过程中,当星期六与DataGridView中存在的数据不符时,它会经过。
我该怎么做?
这是我的代码:
Private Sub btnSabatoVecchio_Click(sender As Object, e As EventArgs) Handles btnSabatoVecchio.Click
d1.Value = GetRandomDate(d1.MinDate, d1.MaxDate)
Dim table As New DataTable()
Dim command As New SqlCommand("SELECT * FROM LottoDeaBendata WHERE [Data] BETWEEN @d1 AND @d2", connection)
d1.Value = d1.Value.AddDays(DayOfWeek.Sunday - (d1.Value.DayOfWeek + 1))
d2.Value = d1.Value
command.Parameters.Add("@d1", SqlDbType.Date).Value = d1.Value
command.Parameters.Add("@d2", SqlDbType.Date).Value = d2.Value
Dim adapter As New SqlDataAdapter(command)
adapter.Fill(table)
DataGridView1.DataSource = table
End Sub
当我只在这种情况下将日期随机对日期进行随机化时,如果没有数据的对应关系,我希望它通过下周六以外的时间,直到在该日期(星期六)找到现有数据为止。
My code looks for me only on Saturdays, but in random it also looks for Saturdays that are not present in my table, for example Saturday November 2nd, I have no data, I would like it to skip those dates that have no data to display in DataGridView. So when randomizing the datatimepichker, I would like it to skip those dates or Saturdays that don't match anything in my table and then move past that is to next Saturday, until it finds the date that matches a full row and not null. 2
With a button, I created the possibility to search through 2 DateTimePicker (1 and 2) the targeted search, in this case only on Saturdays, of data that I have in the table and that I display with a DataGridView.
What I would like is that in the random of Saturdays, it passes over when the Saturday does not correspond to the data present in the DataGridView.
How do I do this?
Here is my code:
Private Sub btnSabatoVecchio_Click(sender As Object, e As EventArgs) Handles btnSabatoVecchio.Click
d1.Value = GetRandomDate(d1.MinDate, d1.MaxDate)
Dim table As New DataTable()
Dim command As New SqlCommand("SELECT * FROM LottoDeaBendata WHERE [Data] BETWEEN @d1 AND @d2", connection)
d1.Value = d1.Value.AddDays(DayOfWeek.Sunday - (d1.Value.DayOfWeek + 1))
d2.Value = d1.Value
command.Parameters.Add("@d1", SqlDbType.Date).Value = d1.Value
command.Parameters.Add("@d2", SqlDbType.Date).Value = d2.Value
Dim adapter As New SqlDataAdapter(command)
adapter.Fill(table)
DataGridView1.DataSource = table
End Sub
when I randomize the dates in this case only on Saturdays, if there is no correspondence of data, I would like it to pass beyond the next Saturday, until existing data is found with that date (Saturday).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论