Dim con1 As OleDb.OleDbConnection
Dim cmd As OleDb.OleDbCommand
Dim query As String
Dim rs As OleDb.OleDbDataReader
con1 = New OleDb.OleDbConnection("Provider=MSDAORA.1;Data Source=localhost;Persist Security Info=True;Password=sys;User ID=nitishok")
con1.Open()
query = "select * from HOLDERSDB where DOB like '" + DateTimePicker1.Value + "' "
cmd = New OleDb.OleDbCommand(query, con1)
cmd.CommandType = CommandType.Text
rs = cmd.ExecuteReader
Dim da As New OleDb.OleDbDataAdapter(query, con1)
Dim ds As New DataSet()
da.Fill(ds, "HOLDERSDB")
DataGridView1.DataSource = ds.Tables(0)
con1.Close()
enter code here
i want rows from HOLDERS table that have DOB as datetimepicker1
The code that i have posted does not return any results.
Plz help.
assuming DOB is a DATE field (hopefully it is!)
then use TO_DATE and don’t try to compare date=string, otherwise your code will fail if not today then someday.
see here to format the return of DateTimePicker
http://msdn.microsoft.com/en-us/library/system.windows.forms.datetimepicker.customformat.aspx
make sure to format it the same way as the 2nd parameter (doesnt have to be dd-mon-yyyy as i put, Oracle supports multiple formats) in the TO_DATE function.
also you should be using bind variables and not pasting strings into the SQL anyway for performance / security reasons.