|
-
Sep 6th, 2009, 01:01 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Problems with the DataGridView!!!
I want to fetch some data from the database to the DataGridView,so i did this code:
Code:
Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Etech.mdb"
Dim myConnection As OleDbConnection = New OleDbConnection
myConnection.ConnectionString = connString
Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select LAcNo,IssuerName,Creditor,Amount,ROI,EMIAmount,BankAcNo,CreditCardNo,Notes from MLoan", myConnection)
Dim ds As DataSet = New DataSet
DataGridView1.Columns(0).DataPropertyName = "LAcNo"
DataGridView1.Columns(1).DataPropertyName = "IssuerName"
DataGridView1.Columns(2).DataPropertyName = "Creditor"
DataGridView1.Columns(3).DataPropertyName = "Amount"
DataGridView1.Columns(4).DataPropertyName = "ROI"
DataGridView1.Columns(5).DataPropertyName = "EMIAmount"
DataGridView1.Columns(6).DataPropertyName = "BankAcNo"
DataGridView1.Columns(7).DataPropertyName = "CreditCardNo"
DataGridView1.Columns(8).DataPropertyName = "Notes"
da.Fill(ds, "MLoan")
Dim dt As New DataTable
da.Fill(dt)
DataGridView1.DataSource = dt
Now in the select statement i want to apply a condition that select only those rows from the database where ReminderDate=TodayDate
The date format in my access database is like this:
Attachment 73017
but i cant build up the select statement.....the select statement that i gave above,what will be the where portion then?
ReminderDate=Today.Date will wont work i wish;then what will be the where portion in my select query?
Last edited by gautamshaw; Feb 21st, 2010 at 01:21 PM.
-
Sep 6th, 2009, 01:37 AM
#2
Thread Starter
Frenzied Member
Re: Problems with the DataGridView!!!
ReminderDate is a column present in my database......
I dont want to show that column in the DataGridView......with the help of that ReminderDate of the database i want to fetch only those columns where the ReminderDate matches the today date.......
How to modify the select query?
-
Sep 6th, 2009, 01:57 AM
#3
Re: Problems with the DataGridView!!!
Select LAcNo,IssuerName,Creditor,Amount,ROI,EMIAmount,BankAcNo,CreditCardNo,Notes from MLoan WHERE ReminderDate BETWEEN CAST(CONVERT(GetDate(), VARCHAR(24),101) + '00:00:00' AS DATETIME) AND CAST(CONVERT(GetDate(), VARCHAR(24),101) + '23:59:59' AS DATETIME)
That should do it. The only funny business is so that the entire day is covered (12am - 11:59 am).
-
Sep 6th, 2009, 02:04 AM
#4
Thread Starter
Frenzied Member
Re: Problems with the DataGridView!!!
I get this exception:
Attachment 73020
Last edited by gautamshaw; Feb 21st, 2010 at 01:21 PM.
-
Sep 6th, 2009, 02:15 AM
#5
Re: Problems with the DataGridView!!!
Maybe Access doesn't have GetDate() I was thinking SQL.
Try switching GetDate to Now. Actually I'm not sure it has CAST or CONVERT either.
Maybe try this (Sorry my Access is way rusty)
Select LAcNo,IssuerName,Creditor,Amount,ROI,EMIAmount,BankAcNo,CreditCardNo,Notes from MLoan WHERE ReminderDate = DATEVALUE(Now())
-
Sep 6th, 2009, 02:19 AM
#6
Thread Starter
Frenzied Member
Re: Problems with the DataGridView!!!
This time no rows are selected.....
Any alternative solution?
-
Sep 6th, 2009, 02:23 AM
#7
Re: Problems with the DataGridView!!!
I'm too rusty on Access. The problem is most likely time. You should use a BETWEEN but I don't know if you can concat time onto a date in Access. You'll have to google around for the answer or wait for someone else to answer. It will be something like this:
Select LAcNo,IssuerName,Creditor,Amount,ROI,EMIAmount,BankAcNo,CreditCardNo,Notes from MLoan WHERE ReminderDate BETWEEN DATEVALUE(Now()) + '00:00:00' AND DATEVALUE(Now()) + '23:59:59'
-
Sep 6th, 2009, 02:32 AM
#8
Thread Starter
Frenzied Member
Re: Problems with the DataGridView!!!
I tried the query that you gave;i get this exception:
Attachment 73021
The datatype of ReminderDate is set to text in the access Database.......
Do i need to change this select query:
Code:
Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select LAcNo,IssuerName,Creditor,Amount,ROI,EMIAmount,BankAcNo,CreditCardNo,
Notes from MLoan WHERE ReminderDate BETWEEN DATEVALUE(Now()) + '00:00:00' AND DATEVALUE(Now()) + '23:59:59' ", myConnection)
Last edited by gautamshaw; Feb 21st, 2010 at 01:21 PM.
-
Sep 6th, 2009, 06:45 AM
#9
Thread Starter
Frenzied Member
Re: Problems with the DataGridView!!!
i just googled through a few pages and i got this:
Attachment 73027
So i modified my query to this:
Code:
Dim da As OleDbDataAdapter = New OleDbDataAdapter
("Select LAcNo,IssuerName,Creditor,Amount,ROI,EMIAmount,BankAcNo,
CreditCardNo,Notes from MLoan where ReminderDate=Today ", myConnection)
But when i execute the application,i am getting this exception:
Attachment 73028
Any hints?
Last edited by gautamshaw; Feb 21st, 2010 at 01:21 PM.
-
Sep 6th, 2009, 08:53 AM
#10
Thread Starter
Frenzied Member
Re: Problems with the DataGridView!!!
I tried this:
Code:
Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Etech.mdb"
Dim myConnection As OleDbConnection = New OleDbConnection
myConnection.ConnectionString = connString
Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select LAcNo,IssuerName,Creditor,Amount,ROI,EMIAmount,BankAcNo,CreditCardNo,Notes from MLoan where ReminderDate=@reminderdate ", myConnection)
Dim ds As DataSet = New DataSet
DataGridView1.Columns(0).DataPropertyName = "LAcNo"
DataGridView1.Columns(1).DataPropertyName = "IssuerName"
DataGridView1.Columns(2).DataPropertyName = "Creditor"
DataGridView1.Columns(3).DataPropertyName = "Amount"
DataGridView1.Columns(4).DataPropertyName = "ROI"
DataGridView1.Columns(5).DataPropertyName = "EMIAmount"
DataGridView1.Columns(6).DataPropertyName = "BankAcNo"
DataGridView1.Columns(7).DataPropertyName = "CreditCardNo"
DataGridView1.Columns(8).DataPropertyName = "Notes"
cmd.Parameters.AddWithValue("@reminderdate", Today.ToString)
da.Fill(ds, "MLoan")
Dim dt As New DataTable
da.Fill(dt)
DataGridView1.DataSource = dt
This time i am getting this error:
Attachment 73031
Any suggestion please.....
Last edited by gautamshaw; Feb 21st, 2010 at 01:21 PM.
-
Sep 6th, 2009, 11:27 AM
#11
Thread Starter
Frenzied Member
Re: Problems with the DataGridView!!!
I gave another try with the code and i came up with this but in vain:
Code:
Try
Using con As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=Etech.mdb")
con.Open()
cmd = New OleDbCommand("Select LAcNo,IssuerName,Creditor,Amount,ROI,EMIAmount,BankAcNo,CreditCardNo,Notes from MLoan where ReminderDate=@RemDate ", con)
cmd.Parameters.AddWithValue("@RemDate", Date.Now.Date)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As DataSet = New DataSet
da.Fill(ds, "MLoan")
Dim dt As New DataTable
Dim row As DataRow
da.Fill(dt)
DataGridView1.DataSource = dt
For Each row In dt.Rows
DataGridView1.Columns(0).DataPropertyName = "LAcNo"
DataGridView1.Columns(1).DataPropertyName = "IssuerName"
DataGridView1.Columns(2).DataPropertyName = "Creditor"
DataGridView1.Columns(3).DataPropertyName = "Amount"
DataGridView1.Columns(4).DataPropertyName = "ROI"
DataGridView1.Columns(5).DataPropertyName = "EMIAmount"
DataGridView1.Columns(6).DataPropertyName = "BankAcNo"
DataGridView1.Columns(7).DataPropertyName = "CreditCardNo"
DataGridView1.Columns(8).DataPropertyName = "Notes"
Next
End Using
Catch ex As Exception
End Try
No data is selected from the database......
Need some help
thank you
Last edited by gautamshaw; Sep 6th, 2009 at 11:53 AM.
-
Sep 6th, 2009, 10:03 PM
#12
Thread Starter
Frenzied Member
Re: Problems with the DataGridView!!!
-
Sep 6th, 2009, 11:59 PM
#13
Lively Member
Re: Problems with the DataGridView!!!
Do you have your .mdb file? I would like to take a stab at it for you. If so, send it to my email address...
-
Sep 7th, 2009, 12:36 AM
#14
Thread Starter
Frenzied Member
Re: Problems with the DataGridView!!!
I just gave a snapshot of my mdb file in my very first post.......
Have a look at it
-
Sep 7th, 2009, 04:02 AM
#15
Re: Problems with the DataGridView!!!
First if ReminderDate is set as a Text field then change it. It should be a date not text.
Most likely the problem is that the dates are not exact. In your original screen print the dates have times also, which is normal for a database. So unless the dates have a time of midnight then they wont be an exact match to Date.Now.Date. This is why I suggested the BETWEEN statement in my code earlier.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|