Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




EXE Program Don't Populate Access Database Into Datagrid


Hi,
when I copy an exe file to another computer (only window2000 installed, no visual studio and no access installed), the program run but didn't populated data from Access database into the dategrid (It worked with the computer with vb and access installed). Do I need to installed some driver or component to make it work? Thanks.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Populate Datagrid From Access***RESOLVED****
I have a datagrid i wish to populate from an Access 2000 database.
The code is as follows

Code:
Dim strTableNameAs String

'*******
Dim conn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rs As New ADODB.Recordset
'***********

strTableName= lstTables.List(lstTables.ListIndex)
Status frmMain, "Importing Access Database......please wait"
mWait
conn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & lblDBAddress.Caption & ";"
Set cmd.ActiveConnection = conn
cmd.CommandText = "SELECT * FROM " & strTableName & ""
rs.CursorLocation = adUseClient
rs.Open cmd, , adOpenStatic, adLockBatchOptimistic
Set dgData.DataSource = rs


the code goes off without a hitch but columns of data are not displayed, only a blank grid

Do i need to bind the columns to the database columns? How would i do this?

Thanks for the help.

Populate DataGrid From Access DB On Runtime - Help (VB6)
Here's the thing, I have an Access DB with Table1 as my table name with the following Fields.

Date, Code, Roll, Blip

I want to populate my DataGrid by runtime and not by design mode.. I have been searching around and none of the codes I've read have worked. I'm about to give up on using DataGrid and just show it up by listings.. Here's what I've got:

Code:Option Explicit

Private cConn As ADODB.Connection
Private cRs As ADODB.Recordset

Private Sub cmdExit_Click()
    Unload Me
End Sub

Private Sub Form_Load()
    Set cConn = New ADODB.Connection
    cConn.ConnectionString = _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & App.Path & "C.MDB;" & _
        "Persist Security Info=False"
    cConn.Open
    
    Set cRs = New ADODB.Recordset
    cRs.Open _
        "SELECT * FROM Table1", _
        cConn, adOpenStatic, adLockOptimistic
            
    cRs.MoveFirst
    Set dgridC.DataSource = cRs
End Sub


this is what i keep getting. i dont seem to be getting any fields.. am i required to specify the fields and what record is supposed to bind to it? i'm completely lost here and unsure of what to do..

(just so you know, i am with VB6 not .NET)



Edited by - si_coupe on 7/28/2005 4:54:09 AM

VB Program To Populate A Database
I Need to know how to populate a database with users with the following fields...

First Name
Last Name
Email
City
State
Zip
Password


Any thing that you know would be helpful. In addition, i do have an exsisting Program but i don't know if it is right or not... here it is....


Code:
<%
limit = 10
Server.ScriptTimeout = 9999999
dim fname(10)
fname(0) = "dave"
fname(1) = "tom"
fname(2) = "nick"
fname(3) = "dave2"
fname(4) = "Ryan"
fname(5) = "Matt"
fname (6) = "Garry"
fname(7) = "Michael"
fname(8) = "JoeShmoe"
fname(9) = "Robert"
fname(10) = "Zach"





dim email(10)
email(1) = "@yahoo.com"
email(0) = "@something.com"
email(2) = "@msn.com"
email(3) = "@forte.com"
email(4) = "@java.com"
email(5) = "@youknow.com"
email(6) = "@whatever.com"
email(7) = "@hardcoreprogrammer.com"
email(8) = "@ilovejava.com"
email(9) = "@microsoft.com"
email(10) = "@lost.com"

dim lname(10)
lname(0) = "Xier"
lname(1) = "Swav"
lname(2) = "Bair"
lname(3) = "SugarPlum"
lname(4) = "SugarPlump"
lname(5) = "lost"
lname(6) = "Qwerty"
lname(7) = "pwer"
lname(8) = "asdf"
lname(9) = "Yoyoyo"
lname(10) = "Pzerker"





dim city (4)
city (0) = "Here"
city (1) = "There"
city (2) = "Standish"
city (3) = "Sterling"
city (4) = "Hell"





dim state (2)
state (0) = "Michigan"
state (1) = "Washington"
state (2) = "Illinois"
dim zip (9)
zip(0) = 2
zip(1) = 1
zip (3) = 3
zip (4) = 4
zip (5) = 5
zip (6)= 6
zip (7) = 7
zip (8) = 8
zip (9) = 9
dimpw
pw = "password"

goupto = 5000
COUNTER = 0
LIMIT = 10

varLocale = SetLocale(1033)
vardate = FormatDateTime(now(), 2)


STRING_users = "insert into users values('"
f = 0
l = 0
c = 0
s = 0
z = 0
e = 0


looped = 0

'NEW WAY
ziped = 10000



while goupto <> counter
STRING_users = "insert into users values('"


varLocale = SetLocale(1033)
vardate = FormatDateTime(now(), 2)


'FORMAT STRING
STRING_users = string_users & fname(f) & lname(l) & ziped & email(e)
string_users = string_users & "', '" & fname(f) & "', '"
string_users = string_users & lname(l) & "', '"
string_users = string_users & city(c) & "', '"
string_users = string_users & state(s) & "', "
string_users = string_users & ziped & ", 'password')"

string_acctinfo = "insert into acctinfo values ('"
string_acctinfo = string_acctinfo & fname(f) & lname(l) & ziped & email(e)
string_acctinfo = string_acctinfo & "', " & ziped & ",50,50)"

string_transact = "insert into accttransact values ('" & vardate & "',1,'Deposit',50," & ziped & ",'checking',null,null)"
string_transact2 = "insert into accttransact values ('" & vardate & "'," & 2 & ",'Deposit',50," & ziped & ",'savings',null,null)"







'INCREMENT VARIABLE

if f = limit then
f = 0
e = e + 1
end if


if e = limit then
e = 0
l = l +1
end if

if l = limit then
if f = limit and e = limit then
counter = goupto - 1
response.write "limit reached"
end if
l = 0
f = f + 1
else
l = l + 1
end if






c = rnd(1) * 4
s = rnd(1) *2





'response.write "<br>" & string_acctinfo
'response.write "<br>" & string_users
'response.write "<br>" & string_transact
'response.write "<br>" & string_transact2

getit.commandtext = string_acctinfo
set listit = getit.execute

getit.commandtext = string_users
set listit = getit.execute

getit.commandtext = string_transact
set listit = getit.execute

getit.commandtext = string_transact2
set listit = getit.execute

string_users = ""
counter = counter + 1
ziped = ziped + 1
looped = looped + 1
wend


response.write looped








%>


ANY HELP IS GREAT!

Trying Populate A DataGrid In Excel Using An Access Stored Proc As The RecordSource.
Hi all,

I'm trying to populate a DataGrid in Excel using an adodc as the datasource and an Access Stored Procedure as the RecordSource of the adodc. The Query I'm using is below:

SELECT *
FROM ICS_ISSUERS AS a
WHERE a.Issuer_SIF is NULL;

The problem I'm having is that when I go in to the RecordSource dialog box and choose adCmdStoredProc as the Command Type and then try to choose my Stored Procedure it doesn't appear in the drop down list. It appears that the Stored Procedures that are present are either 'Inserts','Deletes' or 'Updates'.

Does anybody know how to get around this problem?

Thanks,

Phil.

Populate ComboBox From Access Database
How can I populate a ComboBox list with a field from an Access database? I've got a ComboBox, and an ADO Data Control. I've set the Data Controls properties to connect to an Access Database. I've set the DataSource of the ComboBox to the ADOData Control, and the DataField to the "Name" Field of the Database. When I run the program, the ComboBox is blank. If I click in the ComboBox, nothing is there. However, if I click the ADOData Control so that it scrolls through the records in the Database, the ComboBox will populate with one record at a time, which leads me to believe that I've got all the Data Binding correct. I'd like to be able to choose a name from the entire list of names in the Name field in the Database without having to scroll through the list of names one at a time with the ADO Data Control. Is there a (simple) way to do this?

How To Populate MSHFlexgrid With MS Access Database
hi everyone,

can somebody tell me how to populate the MSHFlexgrid with the MS Access database?

Populate A Combo Using Access Database
Can anyone give examples of how to use vb to populate a combo box from a table in an access database.

I've used MSRDC control to add information from my form into the access database, how can i use MSDRC to populate my combo?

i've tried something like this...but doesnt work

VB Code:
Private Sub Combo_senders_code_Change() combo_senders_code.Clear Form3.MSRDC1.SQL = "select * from awb where combo_senders_code = '" & combo_senders_code.Text & "'"Form3.MSRDC1.RefreshForm3.Show  'rsfields.MoveFirstDo While Not rsfields.EOFcombo_senders_code.AddItem rsfields("Shortcode").valuersfields.MoveNext Loop


Im very very stuck.!

Populate Listbox With Tables From Access Database
Hello all,

I would like to know how to populate a listbox with all the available table in a database. I know how to do this with records from a single table on a form_load event, but I would like the list of tables, not the records from a single table. Is this possible? If so, how would I go about doing it?

Thanx in advance.

Cheers

Cannot Populate A Combo Box With Field Values In My Access Database
I want to populate a combo box on my form with a field in my database. I have about 20 records in my database and I want to populate this combo box with the primary key field in that database. There should be 20 entries in the combo box. 1 for each record in my database. I want to populate it on form load and display the items in alphabetical order. As the user changes the selection in this combo box, I want the data on the rest of the form to reflect the record selected in the combo box. I am having trouble getting the combo box to populate from the Access Database. Can anyone tell me what I am doing wrong? My code is below. Thanks in advance for any help you can give me.

CSS_Oncall is my table name.
cboGroup is the name of my combo box.
dat1 is my data control.

Group is the name of the field in the CSS_Oncall table (I want these values in the combo box.)

Code:
Private Sub Form_Load()
Set objRecSet = dat1.Recordset

Dim pstrSql As String

pstrSql = "Select * From CSS_Oncall"

objRecSet.OpenRecordset pstrSql, Conn, adOpenKeyset
cboGroup.Clear
Do While Not objRecSet.EOF
cboGroup.AddItem objRecSet("Group")
objRecSet.MoveNext
Loop
objRecSet.Close

Populate An Access Database From ASCII Text Files
I am writing a VB program (VB6) that creates an Access database with 8 tables, then populates the the tables from  8 corresponding ASCII text files.  I have successfully created the the empty mdb.  Now I need to populate it.  The fields in the ASCII files are not delimited in any way, and each field varies in length (from 2 to 80 characteres).  The number of fields in each of the 8 files varies also (from 13 to 25).  Is there a quick or easy way to populate the Access database from within the VB program?  Or do I have to do it brute force: field by field for each record for each table?  There can be tens of thousands of records in some of the tables, too, or as little as a few hundred.  Also, this program will be used repeatedly on different text files, so it is more than a one time effort.

Thanks,
Jim

VB DataGrid And Access Database
hi,I need a code for linking VB Datagird and table or query in Access 2000 Database. pls help.

Two Datagrid Access The Same Database
I have two datagrid which access the same database but with different query command.

When i insert a data into the database the 1st datagrid list all the records just fine.
(i automatically refresh the datagrid so it can list the updated records).

But when i tried to list all the records on the 2nd datagrid, it didn't list the records at all until i close the form and reopen it again, the 2nd datagrid shows the records.

What could be the problem ?

This is my snippet codes :

Code:'This is when i clicked the command button, it will list the records on the 2nd datagrid
'ObjPerkiraan is the object from class CPerkiraan

Private Sub Cmd_Cari_Id_Perkiraan_Induk_Click()
    ObjPerkiraan.sql = "Select id_perkiraan,nama_perkiraan from master_perkiraan
    where is_Group = -1 order by id_perkiraan"
    ObjPerkiraan.dapatkanRsMasterPerkiraan
    With DG_Id_Perkiraan_Induk
        .Columns(0).Caption = "Id Perkiraan"
        .Columns(1).Caption = "Nama Perkiraan"
        .HeadFont = "Arial"
        .HeadFont.Bold = True
        .Visible = Not DG_Id_Perkiraan_Induk.Visible
    End With
End Sub

'The method from class CPerkiraan
Public Sub dapatkanRsMasterPerkiraan()
    Set rsIdPerkiraanInduk = New ADODB.Recordset
    rsIdPerkiraanInduk.CursorLocation = adUseClient
    rsIdPerkiraanInduk.Open sqlPerkiraan, con, adOpenKeyset, adLockOptimistic
    'rsIdPerkiraanInduk.Resync adAffectAllChapters
    Set FrmMasterPerkiraan.DG_Id_Perkiraan_Induk.DataSource = rsIdPerkiraanInduk
    
    FrmMasterPerkiraan.DG_Id_Perkiraan_Induk.Refresh
    'Set rsMasterPerkiraan = Nothing
End Sub
Thanks.







Edited by - erc on 3/25/2004 9:30:44 PM

Using A DataGrid With Coded Database Access
Hello, I have been stumped on this problem for a while.

I am need of how to correctly write the code to handle access to a database for a datagrid *without* using the ado data control itself.

I have it down pat how to connect to a database via code only for other controls, but with the grid, I get errors about bookmarks or something.

This is for a program I wish to distribute later, and so cannot have the ADO control hard coded with the location of the database.

I have tried taking an ADO control, setting up the connection string, then cut and paste that connection string to the Form Load sub, so I could change it to use app.path, but leaving the connection string blank (in the properties of the control at design time) errors out.

Any suggestions to this would be greatly appriciated! Thank you for your time.

-Greg

Datagrid Saving To A Access Database
Hello

I am using a datagrid and l would like to update and save the contents to the access database. The customer would like to have an excel style grid, that they can navigate and edit details to it, then update. And also they like to be able to add a new record and add that to the database.

I am using the data environment, as l needed to print some reports (working ok)

Code so far.


Code:
'updating
deCustomers.rsCmdCustomers.update

'saving
deCustomers.rsCmdCustomers.save



Many thanks in advance

Steve

Connecting A DataGrid To An Access Database
Hi All

Please help. I've created the following code to connect a DataGrid to an
Access database using ADO code, but the datagrid is empty at run-time? Any
suggestions?

'Add Questions to the Questions List Box
adComm.CommandText = "tblQuestions"
adComm.CommandType = adCmdTable
Set adRS.Source = adComm
adRS.Open
If Not adRS.EOF Then
adRS.MoveFirst
Set grdQuestions.DataSource = adRS
End If

Thanks

Debbie

Opp Access Database Table In DataGrid
Sir,

           How can I Open an Access Database Table in Datagrid when Database is password protected ?

Kunal

Relations Between DataCombox And DataGrid Using Access Database
Well, my problem is basically:

I have an Access DataBase with information about schools. I built a form with 2 combobox and 1 datagrid. I can´t relationate the 2 combobox. I need:

1º - Select rows from the first combox and put only this information at the second (E.g At the first combobox (ComboCountries) I list all countries. So, when I click at the ComboCountries_click() I need to select one country and after, only the cities of that countries will appear (at the second combobox named ComboCities).

At the same time I need put in a datagrid the information of schools relationated with that 2 combox.

2º When a select one row at the datagrid, how can I create a link to another form showing the information of that selecting row?

Who can help me?

Thanks very much!

 

Datagrid, Saving And Updating To Access Database
Hello

I am using a datagrid and l would like to update and save the contents to the access database. The customer would like to have an excel style grid, that they can navigate and edit details to it, then update. And also they like to be able to add a new record and add that to the database.

I am using the data environment, as l needed to print some reports (working ok)

Code so far.

Code:'updating
deCustomers.rsCmdCustomers.update

'saving
deCustomers.rsCmdCustomers.save


Many thanks in advance

Steve

Need Help With Adding Records To Access Database By Using A Datagrid
I have an Access database installed on my Windows NT4 PC.

I am accessing the database table records from a VB6 program
that I wrote. I have the "Working Model Edition" of VB6
installed on my PC.

I am displaying te contents of a user specified table with a
combination of a datagrid control and an ADO data control.
The code which loads the database table contents into the
datagrid is located in a "module" which is included
with the VB project. The display of the data works fine.

I then modified the program to add a "modification" form and
added the "appropriate" new code to the "global items module".
The modification of table records worked fine.

I then created a form and new code to handle "record additions".
The "add a new record" row is displayed at the bottom of the data
grid (i.e. a blank row with a "*"). However, when I position my
cursor into the "add a new record" row I can't type anything. I
even tried setting the ado data control mode parameter to
"adModeReadWrite" at both design time and run time. This did not
solve the problem.

Here is the code from my "global items module" which handles the
display of the datagrid.


Public Sub AddTableContents(strTableName As String)
' Display the specified table in the form "frmTableAdd"
' inside the DataGrid named "dgrAddGrid" using
' an Adodc control. This grid allows record additions.

    frmTableAdd.lblTableAdd.Caption = "Contents of table " & _
            strTableName
    frmTableAdd.adoTableAdd.CommandType = adCmdTable
    frmTableAdd.adoTableAdd.RecordSource = strTableName
    frmTableAdd.adoTableAdd.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;User ID=Admin;Data Source=F:Program FilesMicrosoft Visual StudioVB98
ewBiblio.MDB;Mode=Share Deny None"
    frmTableAdd.adoTableAdd.Mode = adModeReadWrite
    Set frmTableAdd.dgrAddGrid.DataSource = frmTableAdd.adoTableAdd
    frmTableAdd.Show vbModal

    Exit Sub

End Sub


Any ideas on what I have to change in order to be able to add new records ?

TIA for your help.

Puting Data Into A DataBase (VB6, ADO, ACCESS, DataGrid)
Old in basic/vb but new to this part of database with VB6.

Have created an ACESS Database with several tabels.

Have a VB6 project with several forms.
ACESS, ADO, Jet 4.0 and DataGrid.

If I make a textbox and connect it to the database and say
DataBase.Recordset.AddNew
then I can add text into that textbox and this goes into that database.
So far no problem.

But now I want a value I have in a string, TextString, to be put into the database. In fact I have several such strings I want to be put into various Fields in the new Data.

But I am not able to.

Have tryed to put this text into the TextBox. But this does not get transfered into the database. Strange to me as if I type "manually" it does.
Maybee some settings or ---
So how can I send a textstring direct to a field in the database?

Have a nice day
Per

Simultaneous MS Access Database Access Problem Using VB6 Program.
am using MS Access database by a vb6 program for multiuser environment.
In the program I have written code for autogenerating employee_id which is primary key in the table.
When entering records simultaneously from two or more workstation,
It gives a problem

Run time error
The changes you requested to the table were not successful because they would create duplicate values in the primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.

How to resolve it.
Is there any way to restrict the database from accessing when record appending goes on by other workstation.

Populate A Datagrid
Setup:
SQL Database holds User Information [Table: X] which is composed of 4 Columns [ID, Name, Password, Level].

Goal:
I want to display the Results of my SEARCH on the form; from my understanding the best and easiest way would be to use a DataGrid [dg] (correct me if I am mistaken).
The SEARCH is done using SQL Statement “Select” and saves the result as an ADODB.Recordset [rs].

When the search is done, I wish for the Datagrid [dg] to display Columns 2,3,4 [Name, Password, Level] (thus omitting Column1) (if the Datasource was pre-linked I would just retrieve all fields and then play with the properties, however in this case the Datasource is added in the code so this method wont work).

Problem:
I am unable to display the result in my Datagrid [dg], I do not get any “errors” when the program is run however the Datagrid itself never updates. Am I supposed to “format” the Datagrid beforehand (i.e.: right now it is a default 2-Column Grid that I drag/dropped)?
What else is wrong? Do I need to save the Recordset in a more Datagrid-friendly format?

Current Code

Module Code:
Public Sub SearchU(Un As String)
Dim oDB As New clsDB
oDB.SetQuery ("select * from [X] where [Name] = '" + Un + "'")
Set frm1.dg.DataSource = oDB.rs
End Function

Form1 Code:
SearchU (txtaUsername.Text)
dg.Refresh

Any help would be more then appreciated, been on this problem for over 2 days now.

Populate Datagrid Using Sql
i have the following code in the click event of a combobox (cboTeam), i wish to use the data from the combobox to populate a datagrid with the sql code below, or should i use a flexgrid.

Private Sub cboTeam_Click()
txtTeamID.Text = cboTeam.ItemData(cboTeam.ListIndex)
sql = "Select * from player_details where team_id = '" & txtTeamID.Text & "'"

End Sub

Populate Datagrid
Is it possible to populate the datagrid with recordset object other than any bound controls like adodc or datacontrol etc?

here is my code but i ger error as "method or data member not found"

Dim cmd As String
Dim gql As String
Dim cn As ADODB.Connection
Dim grs As ADODB.Recordset
cmd = "provider=microsoft.jet.OLEDB.3.51;Datasource=" & (App.Path & "Anodedata.mdb")
Set cn = New ADODB.Connection
With cn
.ConnectionString = cmd
.Open
End With
gql = "select * from anodedata"
grs.Open gql, cn, adOpenDynamic
Grid1.DataSource = grs ' ****** get error "method or data member not found" *******
grs.Close
Set grs = Nothing
cn.Close
Set cn = Nothing

thanks in advance

Populate A Datagrid
Setup:
SQL Database holds User Information [Table: X] which is composed of 4 Columns [ID, Name, Password, Level].

Goal:
I want to display the Results of my SEARCH on the form; from my understanding the best and easiest way would be to use a DataGrid [dg] (correct me if I am mistaken).
The SEARCH is done using SQL Statement “Select” and saves the result as an ADODB.Recordset [rs].

When the search is done, I wish for the Datagrid [dg] to display Columns 2,3,4 [Name, Password, Level] (thus omitting Column1) (if the Datasource was pre-linked I would just retrieve all fields and then play with the properties, however in this case the Datasource is added in the code so this method wont work).

Problem:
I am unable to display the result in my Datagrid [dg], I do not get any “errors” when the program is run however the Datagrid itself never updates. Am I supposed to “format” the Datagrid beforehand (i.e.: right now it is a default 2-Column Grid that I drag/dropped)?
What else is wrong? Do I need to save the Recordset in a more Datagrid-friendly format?

Current Code

Module Code:
Public Sub SearchU(Un As String)
Dim oDB As New clsDB
oDB.SetQuery ("select * from [X] where [Name] = '" + Un + "'")
Set frm1.dg.DataSource = oDB.rs
End Function

Form1 Code:
SearchU (txtaUsername.Text)
dg.Refresh

Any help would be more then appreciated, been on this problem for over 2 days now.

How Do I Populate A DataGrid From A
How do I populate a dataGrid from a recordset in vb

Populate A DataGrid
Hello!

I would like to know how i can populate a DataGrid or some similar with code.

This will help me to much.

DiogoReis

Populate A Datagrid
Hello. Someone pls help me.

I have 3 tables (patients, treatments and work) in my .mdb file.

Table patiens :
patiens_id
patiens_name

Table treatment :
treatment_id
treatment_name

Table work :
work_id
work_name
patiens_id
treatment_id

I populate a listbox with all patiens_name and i stored patiens_id in a newindex. Everything is ok with this.
When i select a patiens_name from the list box i want to populate a datagrid with patiens_name, treatment_name and work_name.

The problem is how i can connect my datagrid to a database and select only the fields what i want with contidion WHERE.
Something like this :
SELECT patiens_name, treatment_name, work_name FROM work WHERE patiens_id=" & patiens.ItemData(patiens.ListIndex)

patines is the name of the listbox.


www.ovioros.com

Populate Datagrid Row By Row
Can someone tell me how to populate data from recordset to a Datagrid row by row ? (using while statement maybe ?)

Thx.





Edited by - erc on 3/31/2004 2:10:23 AM

I Can't Populate The Datagrid.
I have two tables called Master and Sched.

In my project I have a form called frm_plantilla, within that
form I three textboxes, I called them as txt_studno, text1, & text2.
I also have "Datagrid" in my form and I call this as datagrid1.

My problem is how can I populate my datagrid?
Where I want to load the information from SCHED table to my datagrid.

I have here my codes for more info.

Please Help me, suggestion is highly appreciated.

Thanks,
jay

================================
code
================================


Option Explicit

Private Sub Form_Load()

End Sub


Private Sub Form_Unload(Cancel As Integer)
Me.Hide
End Sub

Private Sub txt_studno_GotFocus()

If txt_studno.Enabled Then
txt_studno.SelStart = 0
txt_studno.SelLength = Len(txt_studno.Text)

End If
End Sub

Private Sub txt_StudNo_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
txt_StudNo_LostFocus
End If
End Sub

Private Sub txt_StudNo_LostFocus()
Dim sql2 As String, rs2 As ADODB.Recordset
Set rs2 = New ADODB.Recordset
sql2 = "SELECT * From master WHERE (((master.CARD_CODE)='" & txt_studno & "'));"
rs2.Open sql2, SetDSNConnection, adOpenDynamic, adLockOptimistic

If rs2.EOF Then
WarningMsg1
Exit Sub
End If

If txt_studno = "" Then
WarningMsg1
Else
LoadInfo

Exit Sub
End If
rs2.Close
SetDSNConnection.Close
Set rs2 = Nothing
End Sub

Private Sub LoadInfo()
Dim sql As String, rs As ADODB.Recordset

Set rs = New ADODB.Recordset

sql = "SELECT sched.FACULTY, master.LASTNAME, master.FIRSTNAME, master.MI, master.Course, master.TITLE, master.DEPARTMENT, sched.PERIOD, sched.TIME, sched.ROOM, sched.SUBJECT, sched.SEC, sched.REMARKS, sched.BLDG FROM master INNER JOIN sched ON master.CARD_CODE = sched.FACULTY WHERE (((sched.FACULTY)='" + txt_studno.Text + "'));"
rs.Open sql, SetDSNConnection, adOpenKeyset, adLockPessimistic

On Error GoTo ErrorHandler:
If rs.RecordCount > 0 Then
Text1 = rs("LastName") & " " & rs("FirstName") & " " & rs("Mi")
Text2 = rs("course") & " " & rs("Title") & " " & rs("Department")

Else
WarningMsg1
End If
rs.Close
SetDSNConnection.Close
Set rs = Nothing

ErrorHandler:
If Err <> 0 Then
WarningMsg1
Else
If txt_studno.Enabled Then
txt_studno.SelStart = 0
txt_studno.SelLength = Len(txt_studno.Text)

End If
End If
End Sub


Private Sub WarningMsg1()
MDIFrmMain.StatusBar1.Panels(1).Text = "Invalid Input!"

txt_studno.SelStart = 0
txt_studno.SelLength = Len(txt_studno.Text)

End Sub

Public Sub DataGrid1()
Dim sql As String, rs As ADODB.Recordset

Set rs = New ADODB.Recordset

sql = "SELECT at_data.ID_No, at_data.Date_Absent, at_data.Subj, at_data.Sect, at_data.Room FROM master INNER JOIN at_data ON master.CARD_CODE = at_data.ID_No WHERE (((at_data.ID_No)='" + txt_studno.Text + "'));"
rs.Open sql, SetDSNConnection, adOpenKeyset, adLockPessimistic

Set DataGrid1.DataSource = rs

End Sub
=======================================

Tutorial On Populating A DataGrid With Data From A Microsoft Access Database
can someone plz tell me how to do this or give me a link to a tutorial

i have been searching the net and this forum for ages and aint been able to find a simple tutorial that explains how to simply add data from an access database to a datagrid on my VB 6 form

Using An SQL String To Call Data From Access Database Into VisualBasic DataGrid???..n
the Situtaion:.. I am using an access database that holds dates as strings. example( 06252004 ). I am trying to use an sql string to search everything that is selected from that database table, for dates specified as a start date and end date, which are specified by the user. The results should be placed on a datagrid.

All my sql attempts have failed.


Can anyone help me peice one together, in an SQL string format, that will work in VB and be accepted by access when vb passes it to it?

Using A Module To Populate Datagrid
Hi

I'm putting together a program that uses a datagrid to show information from a database. In order to keep the code tidy, I wanted to put the datagrid control into a module. This I have done, but when I go to run the program it comes up with the following error

An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll

Additional information: Object reference not set to an instance of an object.

It hightlight the very top statement as being the cause:

Public Class frmLL

How do you get a form to use code in a module? currently I'm accessing it like this:


Code:
Private Sub pnlEditLapSrc_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles pnlEditLapSrc.Paint
addeditlaptopgrid.MakeParentTable()
addeditlaptopgrid.MakeDataRelation()
addeditlaptopgrid.BindToDataGrid()
End Sub
The module contains the following:


Code:
Module addeditlaptopgrid

Private myDataSet As DataSet
Private sqlconnection As System.Data.SqlClient.SqlConnection
Private sqlcommand As System.Data.SqlClient.SqlCommand

Dim loanform As New frmLL


Public Sub MakeParentTable()
' Create a new DataTable.
Dim myDataTable As DataTable = New DataTable("ParentTable")
' Declare variables for DataColumn and DataRow objects.
Dim myDataColumn As DataColumn
Dim myDataRow As DataRow
Dim x, y, srchString

' Create new DataColumn, set DataType, ColumnName and add to DataTable.
myDataColumn = New DataColumn
myDataColumn.DataType = System.Type.GetType("System.Int32")
myDataColumn.ColumnName = "Inventory"
myDataColumn.AutoIncrement = False
myDataColumn.Caption = "Inventory Number"
myDataColumn.ReadOnly = True
myDataColumn.Unique = True
' Add the Column to the DataColumnCollection.
myDataTable.Columns.Add(myDataColumn)

' Create second column.
myDataColumn = New DataColumn
myDataColumn.DataType = System.Type.GetType("System.String")
myDataColumn.ColumnName = "Ram"
myDataColumn.AutoIncrement = False
myDataColumn.Caption = "Ram"
myDataColumn.ReadOnly = False
myDataColumn.Unique = False
' Add the column to the table.
myDataTable.Columns.Add(myDataColumn)

' Create third column.
myDataColumn = New DataColumn
myDataColumn.DataType = System.Type.GetType("System.String")
myDataColumn.ColumnName = "Hdd"
myDataColumn.AutoIncrement = False
myDataColumn.Caption = "Hard Disk"
myDataColumn.ReadOnly = False
myDataColumn.Unique = False
' Add the column to the table.
myDataTable.Columns.Add(myDataColumn)

' Create forth column.
myDataColumn = New DataColumn
myDataColumn.DataType = System.Type.GetType("System.String")
myDataColumn.ColumnName = "OS"
myDataColumn.AutoIncrement = False
myDataColumn.Caption = "Operating System"
myDataColumn.ReadOnly = False
myDataColumn.Unique = False
' Add the column to the table.
myDataTable.Columns.Add(myDataColumn)

' Create fifth column.
myDataColumn = New DataColumn
myDataColumn.DataType = System.Type.GetType("System.String")
myDataColumn.ColumnName = "Network"
myDataColumn.AutoIncrement = False
myDataColumn.Caption = "Network"
myDataColumn.ReadOnly = False
myDataColumn.Unique = False
' Add the column to the table.
myDataTable.Columns.Add(myDataColumn)

' Create sixth column.
myDataColumn = New DataColumn
myDataColumn.DataType = System.Type.GetType("System.String")
myDataColumn.ColumnName = "Modem"
myDataColumn.AutoIncrement = False
myDataColumn.Caption = "Modem"
myDataColumn.ReadOnly = False
myDataColumn.Unique = False
' Add the column to the table.
myDataTable.Columns.Add(myDataColumn)

' Create seventh column.
myDataColumn = New DataColumn
myDataColumn.DataType = System.Type.GetType("System.String")
myDataColumn.ColumnName = "Word"
myDataColumn.AutoIncrement = False
myDataColumn.Caption = "Word"
myDataColumn.ReadOnly = False
myDataColumn.Unique = False
' Add the column to the table.
myDataTable.Columns.Add(myDataColumn)

' Create eighth column.
myDataColumn = New DataColumn
myDataColumn.DataType = System.Type.GetType("System.String")
myDataColumn.ColumnName = "Excel"
myDataColumn.AutoIncrement = False
myDataColumn.Caption = "Excel"
myDataColumn.ReadOnly = False
myDataColumn.Unique = False
' Add the column to the table.
myDataTable.Columns.Add(myDataColumn)

' Create ninth column.
myDataColumn = New DataColumn
myDataColumn.DataType = System.Type.GetType("System.String")
myDataColumn.ColumnName = "Powerpoint"
myDataColumn.AutoIncrement = False
myDataColumn.Caption = "Powerpoint"
myDataColumn.ReadOnly = False
myDataColumn.Unique = False
' Add the column to the table.
myDataTable.Columns.Add(myDataColumn)

' Create tenth column.
myDataColumn = New DataColumn
myDataColumn.DataType = System.Type.GetType("System.String")
myDataColumn.ColumnName = "Access"
myDataColumn.AutoIncrement = False
myDataColumn.Caption = "Access"
myDataColumn.ReadOnly = False
myDataColumn.Unique = False
' Add the column to the table.
myDataTable.Columns.Add(myDataColumn)

' Create eleventh column.
myDataColumn = New DataColumn
myDataColumn.DataType = System.Type.GetType("System.String")
myDataColumn.ColumnName = "Other"
myDataColumn.AutoIncrement = False
myDataColumn.Caption = "Other Apps"
myDataColumn.ReadOnly = False
myDataColumn.Unique = False
' Add the column to the table.
myDataTable.Columns.Add(myDataColumn)

'' Create twelth column.
'myDataColumn = New DataColumn
'myDataColumn.DataType = System.Type.GetType("System.String")
'myDataColumn.ColumnName = "Checked"
'myDataColumn.AutoIncrement = False
'myDataColumn.Caption = "Checked"
'myDataColumn.ReadOnly = False
'myDataColumn.Unique = False
'' Add the column to the table.
'myDataTable.Columns.Add(myDataColumn)

'' Make the ID column the primary key column.
'Dim PrimaryKeyColumns(0) As DataColumn
'PrimaryKeyColumns(0) = myDataTable.Columns("ID")
'myDataTable.PrimaryKey = PrimaryKeyColumns

' Instantiate the DataSet variable.
myDataSet = New DataSet
' Add the new DataTable to the DataSet.
myDataSet.Tables.Add(myDataTable)

'Create three new DataRow objects and add them to the DataTable
sqlconnection.ConnectionString = "workstation id=WKSTN39205;packet size=4096;user id=lluser;data source=CATS-SI38678;persist security info=True;initial catalog=LaptopLoan;password=mar5"
sqlconnection.Open()

'Dim counter = SqlCommand1.CommandText = "Select COUNT(*) from CATStest"
'MsgBox(counter)

'Dim myCount = counter
'MsgBox(myCount)
'SqlConnection1.Close()
'SqlConnection1.Open()
sqlcommand.CommandText = "Select * From Laptop"
sqlcommand.ExecuteNonQuery()
Dim myReader = sqlcommand.ExecuteReader
'rs.open()


'For i = 0 To 2
'myDataRow("ID") = i

For Each x In myReader
myDataRow = myDataTable.NewRow()
myDataRow("Inventory") = myReader.getstring(0)
myDataRow("Ram") = myReader.getstring(1)
myDataRow("Hdd") = myReader.getstring(2)
myDataRow("OS") = myReader.getstring(3)
myDataRow("Network") = myReader.getstring(4)
myDataRow("Modem") = myReader.getstring(5)
myDataRow("Word") = myReader.getstring(6)
myDataRow("Excel") = myReader.getstring(7)
myDataRow("Powerpoint") = myReader.getstring(8)
myDataRow("Access") = myReader.getstring(9)
myDataRow("Other") = myReader.getstring(10)
'myDataRow("Checked") = myReader.getstring(11)
myDataTable.Rows.Add(myDataRow)
Next
sqlconnection.Close()
'Next i
End Sub

Public Sub MakeDataRelation()
' DataRelation requires two DataColumn (parent and child) and a name.
Dim myDataRelation As DataRelation
Dim parentColumn As DataColumn
Dim childColumn As DataColumn
parentColumn = myDataSet.Tables("ParentTable").Columns("Inventory")
End Sub

Public Sub BindToDataGrid()
' Instruct the DataGrid to bind to the DataSet, with the
' ParentTable as the topmost DataTable.
loanform.laptopinfo.SetDataBinding(myDataSet, "ParentTable")
End Sub
End Module
Any ideas?

Populate Datagrid STUCK!!
Please help,
For over a year I have read that

Code:
ADODC=EvilEmpire.Headaches

and I am now in a position where I can begin to release the dependency of some inherited applications from the ADODC. I have read many posts here in the forum and in the MSDN (on line version) regarding using a DataGrid with ADO, and from them have gotten very far along. However I am stuck now.

I can't find the correct code to add the data from the recordset into the datagrid. I'm not sure which methods,properties to use.

If this belongs in the Recycle Bin my apologies and please move it there at your discression.

Here is the code thus far. It all works short of showing me anything in the grid. The commented line give me a "Rowset not available" error.

As always thank you in advance.

Bart


Code:
Option Explicit
Dim sSQL As String
Dim sConn As String
Dim oConn As ADODB.Connection
Dim oRS As ADODB.Recordset
Dim i As Integer
Dim p As Integer


Private Sub Form_Load()
sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=J:MyDatabase.mdb;" & _
" Persist Security Info=False"
sSQL = "SELECT * FROM [TROB2000] WHERE [PENDING]='x'"
Set oConn = New ADODB.Connection
Set oRS = New ADODB.Recordset
oConn.Open sConn
oRS.Open sSQL, oConn, adOpenStatic, adLockPessimistic
oRS.MoveFirst
For i = 0 To oRS.Fields.Count - 1
dgTest.Columns.Add(i).Caption = oRS.Fields.Item(i).Name
Next i

Set dgTest.DataSource = oRS
Do While Not oRS.EOF

'dgTest.Row = p '<----- Error here Rowset Not Available
'p = p + 1
For i = 0 To oRS.Fields.Count - 1
dgTest.Columns.Item(i).Text = oRS.Fields.Item(i).Value '<----Same Error here too
Next i
oRS.MoveNext

Loop



dgTest.Refresh

How Do You Populate A DataGrid From A Record Set?
Hi, I've built a recordset with the various info that i need...i now want my data grid to populate with the info from this rs when i click on the view button.....

currently when i click on the view button, nothing happens - the grid stays empty...

are they more difficult to work with than I originally thought?!

Populate A DataGrid Using Code
What is the best code to populate a DataGrid with code from a database and get the total(currency) from the last column?? Will someone give me a little sample code please?

Populate A Datagrid With Code
What is the best code to populate a DataGrid with code from a database and get the total(currency) from the last column?? Can someone give me a little sample code please?

Every day above ground is a GOOD DAY!!!

Populate Datagrid From Textfile...
Is there any way to populate a datagrid from a comma separated textfile?

In the server explorer i can only select database files, just wondering if the datagrid can be filled
by a text file?



Edited by - SystemLord on 8/5/2003 2:29:13 AM

How To Populate A Listview As Fast As That Of A Datagrid
hello,

my problem is that it takes too much time to additems to a listview when for example we have 9000 records.

Is there a way to make the listview load the data from a table as fast as a datagrid ?

because then, while populating the listview, you can't use the form, you must wait.........

any suggestion or ideas ?

thanks

Populate Datagrid With Stored Procedure
I am trying to populate a datagrid with recordset which I am getting from a stored procedure. I am getting an error message "Rowset position can not be restarted." And also in my adodc control caption it is showing "Record -1 of -1". Instead of Record 1 of 1.

Here are my codes:

Code:
Dim sCriteria, sSQL
Dim iNYCUID As Integer
Dim iAssUID As Integer
sCriteria = Trim(txtSearchCriteria.Text)


Dim dataConn
Set dataConn = New ADODB.Connection

With dataConn
.ConnectionString = varDataPath
.ConnectionTimeout = 30
.Open
End With

Dim cmd
Set cmd = New ADODB.Command

With cmd
Set .ActiveConnection = dataConn
.CommandType = adCmdStoredProc
.CommandText = "udsp_Find2"
.Parameters.Append .CreateParameter("ReturnCode", adInteger, adParamReturnValue)
.Parameters.Append .CreateParameter("companyName", adVarChar, adParamInput, 50)
.Parameters.Append .CreateParameter("nycUID", adInteger, adParamOutput)
.Parameters.Append .CreateParameter("assocID", adInteger, adParamOutput)
.Parameters("companyName") = sCriteria

Set AdodcSearch.Recordset = .Execute

End With

MsgBox AdodcSearch.Recordset.Fields(0)

If AdodcSearch.Recordset.EOF Then

MsgBox "EOF"
Else
MsgBox "Not EOF"
End If


If Not (AdodcSearch.Recordset.BOF Or AdodcSearch.Recordset.EOF) Then
AdodcSearch.Caption = "record " & AdodcSearch.Recordset.RecordCount
recCount = AdodcSearch.Recordset.RecordCount
lblRecCount.Caption = recCount & " total records"


Call populateMSGrid
AdodcSearch.Recordset.MoveFirst

With RecordGrid
.Row = 1
.RowSel = 1
.Col = 0
.ColSel = .Cols - 1
.SetFocus

End With

blGridIsLoaded = True

Else
blGridIsLoaded = False
MsgBox ("no matching records found for your criteria")


End If


Exit Function

errorHandler:
MsgBox Err.Description
End Function

Public Function populateMSGrid()
On Error GoTo errorHandler:

Dim rowNum, rowIncrement As Integer
Dim varGray, varBlue, varGreen, varRed, holdStr As String
Dim s As String

holdStr = ""

RecordGrid.Visible = False
rowNum = 0
RecordGrid.Rows = 3
RecordGrid.Cols = AdodcSearch.Recordset.Fields.Count

Call setGridHeaders

AdodcSearch.Recordset.MoveFirst

While Not AdodcSearch.Recordset.EOF

rowNum = rowNum + 1

RecordGrid.Row = rowNum


With RecordGrid

.Col = 0
.ColWidth(0) = 200

.Col = 1
RecordGrid.Text = (AdodcSearch.Recordset!nycuid)

.Col = 2
RecordGrid.Text = (AdodcSearch.Recordset!nycname)
End With

AdodcSearch.Recordset.MoveNext

If Not AdodcSearch.Recordset.EOF Then
RecordGrid.Rows = RecordGrid.Rows + 1 'increments number of rows

End If

Wend

RecordGrid.Visible = True



Exit Function

errorHandler:
MsgBox Err.Description

End Function

Datagrid Didnt Populate? Cant Display Anything
hi all, i am using vb6, i put a datagrid on my form to display records from my ado recordset, but my datagrid dint display/populate any records though my recordset is populated, wads causing tis? .... need help on this ... how to display records on the datagrid correctly when i return a query ? thx..



Private Sub cmdclick_Click()
Dim myconn As ADODB.Connection
Dim myrecset2 As ADODB.Recordset

Dim strnric As String
Dim strrank As String
Dim strname As String
Dim strunit As String
Dim strvoc As String

strnric = Text1.Text
strrank = Text2.Text
strname = Text3.Text
strunit = Text4.Text
strvoc = Text5.Text

Set myconn = New ADODB.Connection
myconn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:/VBWORKSPACE/TESTADO.MDB;"
myconn.Open

Set myrecset2 = myconn.Execute("INSERT INTO PERS VALUES ('" & strnric & "','" & strrank & "','" & strname & "','" & strunit & "','" & strvoc & "')")

MsgBox "Data added successfully !", , " "

myrecset2.Open "Select * from PERS", myconn, adOpenKeyset, adLockOptimistic, adCmdtxt

myrecset2.MoveFirst


Set DataGrid1.DataSource = myrecset2
DataGrid1.Refresh


myrecset2.Close


myconn.Close

End Sub

Populate Array From DataGrid At Runtime
how to populate value in array from datagrid at runtime so that i can have a running total on the numeric field. Please Help

How To Populate Datagrid Manually From Textboxes
Hi, I was looking for solution, but there's none.
Maybe someone of you guys know the answer.

I want to populate datagrid (or some other grid control) with some data from textbox when that textbox lost focus, and all that without any database.

Thanks in advance.

Populate Dbgrid Or Datagrid Using Code
How can i populate a dbgrid or datagrid using a code without using data control??? or to do it manually....

can you give some sample programs?

this code will show my access db..

Populate Dbgrid Or Datagrid Using Code
How can i populate a dbgrid or datagrid using a code without using data control??? or to do it manually....

this code will show my access db..

Populate Datagrid With Dates LIKE Text
Hi , I have code that I query an access database with input from a text box using the SQL LIKE term. The code works fine with text however when I insert the begiining of dates I get errors like invalid syntax or incomplete syntax or no results at all. This is an example of the line code concerned below.

Adodc1.RecordSource = "Select * From projandpro Where NAME LIKE '%" & Text1 & "%';"

Can anyone help on this. Thanks

Populate DataGrid From Sql Stored Procedure
Dear friends, I want to populate DataGrid , data comes from sql stored procedure, what i should do?

Using A Datagrid To Populate Text Boxes
hi there... i have a datagrid (datagrid1) and depending on which record selected on the data grid i want the details of the record to then populate some textboxes....

i.e. record one selected (Name attribute =John)

i want text1.text = John

could anyone tell me how i can do this?

cheers

&lt;help&gt;Populate A DataGrid Control By SQL Query ??
Hi Guys,

I'm wondering on how to put a Result of a Query from an Access Table into a DataGrid Control?
Here's attached a simple project I would someone help me to get rid of this.

Many Thanks,
Habibalby

Copyright © 2005-08 www.BigResource.com, All rights reserved