Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 13th, 2003, 02:29 AM
Registered User
 
Join Date: Sep 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Load Data using Reader in DataGrid

Hi all,
Could anyone clear my doubt. I use DataReader to get the datas & loaded the listview using it. But for loading the data to datagrid i use datatable filled using the same datareader. I get an error message as
" Column CustomerId does not belong to table dtCusDetails" when adding the fields to a datarow.


The code Follows.
lvoorders is listview name
=======================================
Public Class Form1
    Inherits System.Windows.Forms.Form
    Private Connection As OleDbConnection
    Private Command As OleDbCommand
    Private Reader As OleDbDataReader
    Dim StrConn, StrQry As String
    Dim drow As DataRow
    Dim dtable As DataTable
#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()
        dtable = New DataTable("dtCusDetails")
        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        StrConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\VBProj\Test\AdoOperations\Database\bank. mdb;"
        StrQry = "Select * from tblCustomerDetails"
        Command = New OleDbCommand()
With Command
            .Connection = New OleDbConnection(StrConn)
            .Connection.Open()
            .CommandText() = StrQry
            .CommandType = CommandType.Text
            Reader = .ExecuteReader
        End With
lvoorders.Items.Clear()
        With Reader
            While .Read
                lvoorders.Items.Add(Reader.Item("CustomerName"))
                drow = dtable.NewRow
                drow.Item("CustomerId") = .Item("CustomerId")
                drow.Item("CutomerName") = .Item("CustomerName")
                drow.Item("CustomerSex") = .Item("CustomerSex")
                drow.Item("CustomerAddress") = .Item("CustomerAddress")
    dtable.Rows.Add(drow)
     End While
        End With
     DataGrid1.DataSource = dtable
End Sub
=======================================
thanks in advance
Sen_Prog
:)
 
Old September 20th, 2003, 10:25 AM
Registered User
 
Join Date: Sep 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Check the structure of your tblCustomerDetails table. Maybe you have the "CustomerID" column misspelled. It could be CustID, CustomerNo or anything else. Avoid using the SELECT * ... query. Specify the columns explicitly instead. It's a [u]good</u> coding practice.

Cheers!






Similar Threads
Thread Thread Starter Forum Replies Last Post
chapter6.1.3 :Data Reader Source johe BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 0 November 28th, 2008 04:35 AM
Data reader checking.... janees ASP.NET 1.0 and 1.1 Professional 1 March 11th, 2007 06:09 AM
oracle data reader silvia C# 10 February 2nd, 2006 07:30 AM
Fill data set from data reader sunil menghani ADO.NET 3 March 29th, 2005 07:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.