[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

Selecting a record based on the date entered

Hi Guys! I have an access database with few records in it. I am in the process of generating reports based on few criterias. I have text box called txtdate which holds the date entered by the user. Based on the date, the records should be displayed on the datagrid. I can use the empid, and other fields, but its not working with the date field, Please guide me as to what i am doing wrong. The date field in the database is called adate. Also, when the data is displayed in the datagrid, is there any way where I can export it to excel. Thanks in advance
Dim con As New System.Data.OleDb.OleDbConnection
        Dim dreader As System.Data.OleDb.OleDbDataReader
        Dim myCommand As New System.Data.OleDb.OleDbCommand
        Dim myPath As String
 
        myPath = Server.MapPath("hayat.mdb")
        con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data source=" & myPath & ";"
        myCommand.CommandText = "select * from empattendence where adate = " & txtdate.Text & ""
        myCommand.Connection = con
        Try
            con.Open()
            dreader = myCommand.ExecuteReader
 
            DataGrid1.DataSource = dreader
            DataGrid1.DataBind()
            dreader.Close()
        Catch ex As Exception
            lblerror.Text = "There is an error" + ex.ToString
 
            con.Close()
        End Try

Open in new window

0
preethamonline
Asked:
preethamonline
  • 5
  • 3
1 Solution
 
Ryan ChongCommented:
quick try:

myCommand.CommandText = "select * from empattendence where adate = #" & txtdate.Text & "# "


and make sure value of txtdate.Text in format of mm/dd/yyyy, or yyyy/mm/dd, etc, if it's not, you may need add extra code to format the value into proper date format.
0
 
preethamonlineAuthor Commented:
thanks very much. works like a gem. If you could also tell me as to how do i export these values from the datagrid into excel
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
preethamonlineAuthor Commented:
thanks ryancys. The one click asp.net control seems to be interesting. Would check it and get back to you,
0
 
preethamonlineAuthor Commented:
Dear ryancys, i'm not sure as to why the one click asp.net control is not working . I have added the dll to the tool box and also to the form. The button is called exportbutton1. I have mentioned the other properties but am not able to bind it to the datasource. Do i need to make any modifications to the above code. thanks in advance
0
 
Ryan ChongCommented:
>>Do i need to make any modifications to the above code.

sorry, not testing that example on my local environment.... probably you will need do some customization.

How about trying the 1st 2 links examples? basically just write the data out and set the content type to excel compatible (application/ms-excel)
0
 
preethamonlineAuthor Commented:
ok will try that out. will keep you posted. thanks dear.
0
 
preethamonlineAuthor Commented:
Hi ryancys. Thanks for all your help. I used the above posts and converted the c# code to vb.net and now am able to export the code to excel. Thanks once again.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now