Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 16th, 2004, 04:40 AM
Authorized User
Points: 79, Level: 1
Points: 79, Level: 1 Points: 79, Level: 1 Points: 79, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: , , .
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
Reply With Quote
  #2 (permalink)  
Old August 16th, 2004, 05:35 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Cochin, Kerala, India.
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.
Reply With Quote
  #3 (permalink)  
Old August 16th, 2004, 06:48 AM
Authorized User
Points: 79, Level: 1
Points: 79, Level: 1 Points: 79, Level: 1 Points: 79, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: , , .
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


Reply With Quote
  #4 (permalink)  
Old August 16th, 2004, 11:58 PM
Friend of Wrox
 
Join Date: Oct 2003
Location: Cochin, Kerala, India.
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.
Reply With Quote
  #5 (permalink)  
Old August 17th, 2004, 03:58 AM
Authorized User
Points: 79, Level: 1
Points: 79, Level: 1 Points: 79, Level: 1 Points: 79, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: , , .
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.


Reply With Quote
  #6 (permalink)  
Old August 17th, 2004, 05:51 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Cochin, Kerala, India.
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.
Reply With Quote
  #7 (permalink)  
Old August 17th, 2004, 06:58 AM
Authorized User
Points: 79, Level: 1
Points: 79, Level: 1 Points: 79, Level: 1 Points: 79, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: , , .
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.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:05 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.