enter image description herevb.net I connected the table to textboxes of which one is a datatimepicker, each row of the table has a date each different from the other. the rows of the table have an Id date and text and number values. in visual studio I connected the table to the textbox and datetime picker, what I would like to do is select a date that corresponds to a record and make sure that the corresponding records are seen in the textboxes, how do I do it? Basically I would like browse and filter by date.
Public Sub mostraDati(position As Integer)
Dim command As New SqlCommand("Select * from [dbo].[StoricoLotto]", con)
Dim adapter As New SqlDataAdapter(command)
adapter.Fill(table)
txtId1.Text = table.Rows(0 position)(0).ToString()
dtpDataEstrazione1.Text = table.Rows(0 position)(1).ToString()
txtRuota1.Text = table.Rows(0 position)(2).ToString()
txtEstratto1_1.Text = table.Rows(0 position)(3).ToString()
txtEstratto2_1.Text = table.Rows(0 position)(4).ToString()
txtEstratto3_1.Text = table.Rows(0 position)(5).ToString()
txtEstratto4_1.Text = table.Rows(0 position)(6).ToString()
txtEstratto5_1.Text = table.Rows(0 position)(7).ToString()
End Sub
Solved Like this
Private Sub btnCercaPerData_Click(sender As Object, e As EventArgs) Handles btnCercaPerData.Click
Dim table As New DataTable()
Dim command As New SqlCommand("SELECT * FROM [dbo].[StoricoLotto] WHERE [Data_Estraz]= @dtpDataEstrazione1", con)
command.Parameters.Add("@dtpDataEstrazione1", SqlDbType.Date).Value = dtpDataEstrazione1.Value
Dim adapter As New SqlDataAdapter(command)
adapter.Fill(table)
txtId1.Text = table.Rows(0)("Id").ToString()
dtpDataEstrazione1.Text = table.Rows(0)("Data_Estraz").ToString()
txtRuota1.Text = table.Rows(0)("Ruota").ToString()
txtEstratto1_1.Text = table.Rows(0)("Estratto1").ToString()
txtEstratto2_1.Text = table.Rows(0)("Estratto2").ToString()
txtEstratto3_1.Text = table.Rows(0)("Estratto3").ToString()
txtEstratto4_1.Text = table.Rows(0)("Estratto4").ToString()
txtEstratto5_1.Text = table.Rows(0)("Estratto5").ToString()
End Sub
CodePudding user response:
From your question i understand u want to select data based on date filter, so in ur code simply u add where condition for date filter.
Public Sub mostraDati(position As Integer)
Dim command As New SqlCommand("Select * from [dbo].[StoricoLotto] where [DateColumn]="& datetimpickerID &"", con)
Dim adapter As New SqlDataAdapter(command)
adapter.Fill(table)
txtId1.Text = table.Rows(0)("Id").ToString()
dtpDataEstrazione1.Text = table.Rows(0)("DataEstrazione").ToString()
txtRuota1.Text = table.Rows(0)("Ruota1").ToString()
txtEstratto1_1.Text = table.Rows(0)("Estratto1").ToString()
txtEstratto2_1.Text = table.Rows(0)("Estratto2").ToString()
txtEstratto3_1.Text = table.Rows(0)("Estratto3").ToString()
txtEstratto4_1.Text = table.Rows(0)("Estratto4").ToString()
txtEstratto5_1.Text = table.Rows(0)("Estratto5").ToString()
End Sub
And from filter data if u get multiple rows, that above code only show first row in textboxes.
Thanks and Regards
Aravind