1
I’m new to programming and I’m finishing a job, but I have a problem that I’ve been facing for weeks and I haven’t been able to solve.
I created a simple system that registers the Oss (service orders), and in a form I put a datagrid that pulls all OS.
I made a filter that is to find the employees I type in the text box, but it searches all the services done by the name typed, so I need to know how to make a second filter, where I will inform the initial and final date.
Example: I need to know what the employee did, so I put the employee name in the box and filter, and the services appear on datagrid, however need to know how to make another filter to filter only the dates, then put the dates in another field with a range. ex: 10/10/2014 until 10/20/2014. I have tried some ways but I could not at all.
Could someone explain me, please? I am using VB.NET and Access 2003.
Code:
Dim cn As New OleDb.OleDbConnection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Firebird.mdb"
cn.Open()
Dim dt1 As DateTime = DateTimePicker1.Value.Date
Dim dt2 As DateTime = DateTimePicker2.Value.Date
'MsgBox(dt1)
Try
MsgBox(dt1 + " " + dt2)
Dim cmd As OleDbCommand
Dim dt As DataTable
Dim Da As OleDbDataAdapter
With Cmd
.CommandType = CommandType.Text
.CommandText = "select * FROM OS where data between @datainicial AND @datafinal"
.Parameters.AddWithValue("@datainicial", dt1)
.Parameters.AddWithValue("@datafinal", dt2)
.Connection = cn
End With
With OSTableAdapter.Adapter
.SelectCommand = cmd
dt = New DataTable
.Fill(dt)
OSDataGridView.DataSource = dt
End With
cn.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Could you put in your question an example code?
– Leonel Sanches da Silva
I tried using this code here.. http://pastebin.com/65eS1m0L . however.. I don’t think I need to search the database.. where datagrid already has the results filtered by employee name... I don’t know if I could filter only the dg'data' field.
– Vynicius Henrique
You want to filter the result on
DataTable, that’s it?– Leonel Sanches da Silva
I have a Datagridview.. on it is filtered the name of the employee with all the services performed by him ... I need now filter the range of dates, I need to see the services made by this employee during a certain period... then I tried to include two Datetimepicker one being the initial date, and another the Final Date... I used this code inside the boot filter. However... it didn’t work, I don’t know if I really need to search the bank.. or if you have to filter only the Datagrid column, without having to re-query the database.
– Vynicius Henrique