Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To 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 August 16th, 2004, 04:40 AM
Authorized User
 
Join Date: Aug 2004
Posts: 11
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to bisigreat
Default populate data from Access Table into datagrid

Kindly help, i want to populate data from my access table into datagrid but i got this complain "run-time error '6147' column not found [1

Below is my code
Dim findstr As String
    Dim cnn2 As ADODB.Connection
    Dim rsSearch As ADODB.Recordset
    If txtFind.Text = Empty Then
        MsgBox "Enter the information to seach"
        txtFind.SetFocus
        Exit Sub
    End If
    findstr = "select * from CardCategory where Code = '" & txtFind.Text & "'"
    Set cnn2 = New ADODB.Connection
    cnn2.ConnectionString = "provider=microsoft.jet.oledb.4.0;" & "Data Source = C:\BB\sh.mdb"
    cnn2.Open
    Set rsSearch = New ADODB.Recordset
    rsSearch.Open findstr, cnn2, adOpenDynamic
    If rsSearch.EOF And rsSearch.BOF Then
        MsgBox "Invalid Entry", vbOKOnly, "Stop!!"
        Exit Sub
    End If
    Do While Not rsSearch.EOF
        DataGrid1.Columns(0).Value = rsSearch!Code
        DataGrid1.Columns(1) = rsSearch!Description
    Loop
 
Old August 16th, 2004, 05:35 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

I am doing this in the following way.

I put a data control in the form. Then I connect datagrid with the control using the data source property. Then I change the query property of data control. Then refresh both datacontrol and datagrid.

Unfortunately, I don't have a sample code. You can find a lot from MSDN.

You can right-click datagrid and select retrieve fields. Then you can adjust the widths of coulumns also. This is possible only if you connect datagrid with a data control.
 
Old August 16th, 2004, 06:48 AM
Authorized User
 
Join Date: Aug 2004
Posts: 11
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to bisigreat
Default

Thanks for the response. The data populated well using data control and setting the data field property but the data i need to be populated on the grid is based on my search criteria (txtFind.text)
The major problem is this line
DataGrid1.Columns(0).Value = rsSearch!Code
May be that's not the way to access the first column of a data grid or to put it in a better way, how can i access d columns of a datagrid in order to put data from database in it
Thanks


 
Old August 16th, 2004, 11:58 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

I don't think you can access one particular column of a datagrid and change its values if it is associated with a data control.

In similar situations, I am using a MS Flex grid control.
 
Old August 17th, 2004, 03:58 AM
Authorized User
 
Join Date: Aug 2004
Posts: 11
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to bisigreat
Default

Thanks madhukp. I am not changing the values in the datagrid. I just want to populate data into it based on searching the table for a particular code like "FC"
This is my table
     Code Description
     FC Family Card
     PC Private Card
     FC Family Card

Now i want to type code "FC" in a textbox and click a find button that will trigger a search operation, look for all entries with codes "FC" in my table and populate all such entries in a datagrid. Is this possible from my line of codes above. My major problem has been how to assign code from my table to code column in the data datagrid and how to assign the description to Description column in the datagrid.The program gives error when it gets to this line
        DataGrid1.Columns(0) = rsSearch!Code
        DataGrid1.Columns(1) = rsSearch!Description

How can i assign d values to each column. Kindly help out.


 
Old August 17th, 2004, 05:51 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

I assume you are using a data control and a db grid. Let their names be
dtaTest and dbgTest. The required code is given below.

dtaTest.RecordSource = "select * from CardCategory where Code = '" & txtFind.Text & "'"
dtaTest.Refresh
dbgTest.Refresh

I assume that dbgTest has its DataSource set as dtaTest.
 
Old August 17th, 2004, 06:58 AM
Authorized User
 
Join Date: Aug 2004
Posts: 11
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to bisigreat
Default

Thanks mate, it's now working
i'm actually using adodc and was able to manipulate it with d code u sent. Thanks a million.






Similar Threads
Thread Thread Starter Forum Replies Last Post
populate a drop list fro a data table greenbriar ADO.NET 2 July 22nd, 2008 10:18 PM
Populate a List Box with Table Names & Table date hewstone999 Access VBA 1 February 27th, 2008 10:10 AM
how to populate a table with xml data in xslt miccipynewbie XSLT 6 May 28th, 2007 07:29 AM
Auto-populate table data into form jeff394 Access VBA 2 April 19th, 2006 02:55 PM
Populate a Variable From Access Table sirmilt Access 5 March 21st, 2006 01:34 AM





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