Results 1 to 9 of 9

Thread: MS Access 2003 and VB. NET

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2005
    Posts
    331

    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.

  2. #2
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    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.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: MS Access 2004 and VB. NET

    Did I miss the release of Access 2004?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2005
    Posts
    331

    Re: MS Access 2004 and VB. NET

    Sorry man I meant 2003!

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2005
    Posts
    331

    Re: MS Access 2004 and VB. NET

    Quote 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.

  6. #6
    New Member
    Join Date
    Dec 2005
    Posts
    2

    Re: MS Access 2003 and VB. NET


  7. #7
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: MS Access 2003 and VB. NET

    you just concat the variables into your connection string...
    VB Code:
    1. Dim UserName as String = TextBox1.text
    2. Dim PassWord as String = TextBox2.Text
    3. Dim StrConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;User Id=" & _
    4. [B]UserName[/B] & ";Password=" & [B]PassWord[/B] & ";"
    5. 'strconn would be the connection string variable you use in your data adapters...

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2005
    Posts
    331

    Re: MS Access 2003 and VB. NET

    Quote Originally Posted by gigemboy
    you just concat the variables into your connection string...
    VB Code:
    1. Dim UserName as String = TextBox1.text
    2. Dim PassWord as String = TextBox2.Text
    3. Dim StrConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;User Id=" & _
    4. [B]UserName[/B] & ";Password=" & [B]PassWord[/B] & ";"
    5. '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?

  9. #9
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    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:
    1. Dim strTable As String = "MyTableName" 'remember, if table has spaces, place it in brackets
    2.     Dim DBPath as String = "C:\mydatabase.mdb" 'change to your database name
    3.     Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    4.                       "Data Source=" & DBPath & ";" 'connection string to the msaccess database
    5.     Dim MyDataSet As New System.Data.DataSet
    6.     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
    7.     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
    8.     MyAdapter.Fill(MyDataSet) 'connects to the database, fills dataset with data
    9.     DataGrid1.DataSource = MyDataSet.Tables(0) 'sets datagrid source to the dataset, displays results
    10.     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
  •  



Click Here to Expand Forum to Full Width