?
Solved

Display selected field on the datagrid

Posted on 2009-04-19
9
Medium Priority
?
248 Views
Last Modified: 2012-05-06
Hi Guys! I want to display values from the database on to the datagrid. All seems to work when the sql stmt reads as
myCommand.CommandText = "select * from empattendence where adate = #" & txtdate.Text & "#"
but when i select particular fields to display, it gives an error. The following is the sql that i am trying to use
myCommand.CommandText = "select empid,empname,empdesignation,dhours,othours from empattendence where adate = #" & txtdate.Text & "#"
Please let me know what is to be changed in the code. 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 empid,empname,empdesignation,dhours,othours 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
Comment
Question by:preethamonline
  • 5
  • 3
9 Comments
 
LVL 8

Accepted Solution

by:
bedanand earned 1200 total points
ID: 24179195
Please check  the bound columns on the data grid. You might be binding the column that the query result doesnot contains that column.

Txs
Bedanand
http://www.dot4pro.com

0
 
LVL 14

Expert Comment

by:amar31282
ID: 24179508
what is the error coming in lblerror
0
 

Author Comment

by:preethamonline
ID: 24180101
Hi guys, will check out the solution and post in a few minutes. Sorry was away.
0
Technology Partners: 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!

 

Author Comment

by:preethamonline
ID: 24180123
Dear bedanand, you were absolutely right. The date field was bound to the datagrid and hence the error. Actually i had bound the date field to the datagrid as to format it like {0:d}. But when the date field is displayed in the datagrid, it appears as 4/19/2009 12:00:00 AM. How do i make it appear as just 4/19/2009
0
 
LVL 8

Expert Comment

by:bedanand
ID: 24181949
Hi,

Are u binding like this.

<asp:BoundField DataField="MyDate" DataFormatString="{0:d}" />
If its like this it should work.
Or you can also bind like this

<asp:BoundField DataField="MyDate" DataFormatString="{0:MM/dd/yyyy}" />


Regards
Bedanand
http://www.dot4pro.com


0
 

Author Comment

by:preethamonline
ID: 24182046
where should i eneter this code
0
 

Author Comment

by:preethamonline
ID: 24182108
I get an error message saying that active schema does not support the element <asp:boundfield>
0
 
LVL 8

Expert Comment

by:bedanand
ID: 24182578
Put on the columns section of gridview.

0
 

Author Comment

by:preethamonline
ID: 24182754
Thanks bedanand, i managed to solve it. Basically i made autogeneratecoloumns = false and then bound the columns which i needed to display to the grid. This gave me more options to make it presentable.
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Loops Section Overview
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question