|
-
Dec 18th, 2005, 12:02 AM
#1
Thread Starter
Hyperactive Member
MS Access 2003 and VB. NET
Is it possible to make these two programs work together? I make a database in MS Access, and I can use VB. NET to login into the account that is on the database.
Last edited by 3dmaker; Dec 18th, 2005 at 03:00 PM.
-
Dec 18th, 2005, 12:21 AM
#2
Re: MS Access 2004 and VB. NET
yes, its possible, you just assign the login in the connection string. You can check out http://www.connectionstrings.com in order to find the string you need... You would then use oledb connection objects and data adapters in order to access it...
EDIT: here's a sample...
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;User Id=admin;Password=;"
**i believe you would need the full path to the database in the datasource
Last edited by gigemboy; Dec 18th, 2005 at 12:25 AM.
-
Dec 18th, 2005, 08:44 AM
#3
Re: MS Access 2004 and VB. NET
Did I miss the release of Access 2004?
-
Dec 18th, 2005, 12:50 PM
#4
Thread Starter
Hyperactive Member
Re: MS Access 2004 and VB. NET
-
Dec 18th, 2005, 03:01 PM
#5
Thread Starter
Hyperactive Member
Re: MS Access 2004 and VB. NET
 Originally Posted by gigemboy
yes, its possible, you just assign the login in the connection string. You can check out http://www.connectionstrings.com in order to find the string you need... You would then use oledb connection objects and data adapters in order to access it...
EDIT: here's a sample...
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;User Id=admin;Password=;"
**i believe you would need the full path to the database in the datasource
Thanks for the example, but how would I make it so like I have 2 text boxes. Username and Password. A person types in his info and logs in.
-
Dec 18th, 2005, 04:37 PM
#6
New Member
Re: MS Access 2003 and VB. NET
-
Dec 18th, 2005, 04:41 PM
#7
Re: MS Access 2003 and VB. NET
you just concat the variables into your connection string...
VB Code:
Dim UserName as String = TextBox1.text
Dim PassWord as String = TextBox2.Text
Dim StrConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;User Id=" & _
[B]UserName[/B] & ";Password=" & [B]PassWord[/B] & ";"
'strconn would be the connection string variable you use in your data adapters...
-
Dec 18th, 2005, 05:06 PM
#8
Thread Starter
Hyperactive Member
Re: MS Access 2003 and VB. NET
 Originally Posted by gigemboy
you just concat the variables into your connection string...
VB Code:
Dim UserName as String = TextBox1.text
Dim PassWord as String = TextBox2.Text
Dim StrConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;User Id=" & _
[B]UserName[/B] & ";Password=" & [B]PassWord[/B] & ";"
'strconn would be the connection string variable you use in your data adapters...
Ok, so I have a form with textbox1 and textbox2, and a button. When I press the button how do I activate StrConn?
-
Dec 18th, 2005, 05:15 PM
#9
Re: MS Access 2003 and VB. NET
You're getting all into the basic matters of using ADO.NET, best to read up on it... but here is a post I had made a few days ago... the strconn would be changed to include the username and password, like my above posts...
_____
Here some sample code from a project I had done, all the objects are created in code, with no objects dragged to the form in designer.. a datagrid1 should be created in order to display the results..
VB Code:
Dim strTable As String = "MyTableName" 'remember, if table has spaces, place it in brackets
Dim DBPath as String = "C:\mydatabase.mdb" 'change to your database name
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & DBPath & ";" 'connection string to the msaccess database
Dim MyDataSet As New System.Data.DataSet
Dim MyAdapter As New System.Data.OleDb.OleDbDataAdapter("SELECT * FROM " & strTable, strConn) 'strconn was the connection string i posted above, strTable is a variable with the table name
Dim MyCmdBuilder As New System.Data.OleDb.OleDbCommandBuilder(MyAdapter) 'this is just used if you want to insert or update the database later, not required if you are just viewing the data
MyAdapter.Fill(MyDataSet) 'connects to the database, fills dataset with data
DataGrid1.DataSource = MyDataSet.Tables(0) 'sets datagrid source to the dataset, displays results
DataGrid1.Focus()
Of course, this is without the Try / Catch blocks for errors, so you would eventually put them in, in order to catch errors with the connection, etc
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|