Accessing Database in Various Forms

supersasizza

Member
Joined
Sep 9, 2005
Messages
6
Programming Experience
1-3
HI all,

I'm trying to get a Database to be used in the whole program. What I mean by this is I want my form 1, 2 and 3 to be able to access the same database and table.

Can anyone give me an example on how to do this?

Is there any way you can declare a database globally, and how do you call it if you can?

Thank you,

Sasizza
 
You could access the database if you have a connection. Make the connection in your main form then pass that connection to the form's contractor.
 
Databases continued

Hi guys thanks for the reply but how would I do this in code?


I'm not sure how to declare the variable for a database..


Thanks again
 
The results of a database query are typically stored in a System.Data.DataSet or System.Data.DataTable object. Look in the Database/Back-end section of this forum for examples.
To declare a global variable, one method would be to create a module and declare the variable there.
 
supersasizza said:
Hi guys thanks for the reply but how would I do this in code?
I'm not sure how to declare the variable for a database..
Thanks again

You dont as such need to do this... Im not entirely sure you understand the concepts but once you have a database that is made up of tables, you can create as many forms as you want to interact with those tables... what you will need to declare however are connections to this database... you dont need to declare a database globally, its either available or its not in the simplest of terms. There's a lot to take in really but their is enough content on this site to help you. Try using the search function here as I think youll find this really useful...

hth
 
declare a table globally

add a module to your project called "Public Variables"
add variable declarations there:
ex:
Public tblTemp As DataTable

Access the dataset and set it to you public datatable.
tblTemp = DsTableName1.Tables("TableName")


Declaring a variable for the dabase/connection would be:
Public MyConnection As String = "your connection string here"

Is that what you are asking?
 
Thank you for the replies

I think that might do it.

I'm going to try it again later... and if anyone else has any other ideas please let me know as well... thank you,

If you could show me by code i'd appreciate it as well... just makes it clearer.

Thank you,

Antonio
 
Back
Top