Support Forums

Full Version: Is there anyone here with a good knowledge working with Visual Basic + Access DB?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I keep trying to figure out something that seems to be easy. But I've tried getting help from other coding forums and can't get any. So is there anyone here with a nice knowledge on working with these two programs together?
Hmmm, I am not too sure on using databases. Ask KoBE, he might be of assistance and wait for others to reply. I never use any databases in VB.NET ever. :S
Yeah. I heard Kobe is a great coder. I would message him if I were you.
Alright thanks guys, I'll PM this KoBe dude. ;) <3
I have had lots of past experience using both together for many programs although I'm probaly a bit rusty now.
I can try to help if you have questions.
(04-24-2011, 02:57 AM)Untouch Wrote: [ -> ]I have had lots of past experience using both together for many programs although I'm probaly a bit rusty now.
I can try to help if you have questions.
Okay my friend, so let me try to explain what's my problem as clearly as possible:

Basically, what I need to do is to bind TWO different database tables to ONE textbox in VB. The program itself is meant to have like multiple buttons on 'Form 1' and a textbox on 'Form 2' in which the user is supposed to insert a value which will then go to an Access database. But here's the hard part: IF the user presses 'Button 1' on 'Form 1', the Value inserted on 'Form 2' will go to a field in the database whereas if the user presses 'Button 2' to open 'Form 2', then the value will go to somewhere else and so on.

Now, this can be done using "Case". But the problem is that once the values are loaded into the textbox, I can't get them to save to the database. This is because I binded the textbox to the database using OleDbDataAdapter and OleDbDataConnection...

So basically I need to know how can you bind a database to VB using code only AND get it to save to the database...

I'm sorry if it sounds too confusing. Please see if this helps understanding: http://img849.imageshack.us/i/83594779.png/
Well my laptop doesn't have vb on it so I'll check my computer tomorrow for some of my past projects.
I may be able to give you a full past project which would help with all the code doing this.
(04-23-2011, 07:02 PM)ReactioNz Wrote: [ -> ]Yeah. I heard Kobe is a great coder. I would message him if I were you.

Who is this KoBE guy everyone speaks of? He sounds pretty coolPirate

(04-24-2011, 10:45 AM)Psycho Mantis™ Wrote: [ -> ]Okay my friend, so let me try to explain what's my problem as clearly as possible:

Basically, what I need to do is to bind TWO different database tables to ONE textbox in VB. The program itself is meant to have like multiple buttons on 'Form 1' and a textbox on 'Form 2' in which the user is supposed to insert a value which will then go to an Access database. But here's the hard part: IF the user presses 'Button 1' on 'Form 1', the Value inserted on 'Form 2' will go to a field in the database whereas if the user presses 'Button 2' to open 'Form 2', then the value will go to somewhere else and so on.

Now, this can be done using "Case". But the problem is that once the values are loaded into the textbox, I can't get them to save to the database. This is because I binded the textbox to the database using OleDbDataAdapter and OleDbDataConnection...

So basically I need to know how can you bind a database to VB using code only AND get it to save to the database...

I'm sorry if it sounds too confusing. Please see if this helps understanding: http://img849.imageshack.us/i/83594779.png/

I think I got an idea of what you want... I will throw a sample project together and see if that helps.
alright guys thanks for taking the time to help me. I'll be waiting ;) <3
Here this should help you get started. Since I don't know the schema of your database, I created a sample database. I made a sample project that demonstrates adding Values to a database table and reading from the same table. The code can easily be modified to suit your needs and to add to/read from multiple tables. If you need any help, respond and someone will help you out.

Code:
Imports System.Data.OleDb
Public Class Form1
    Dim SQL As String                           'holds the SQL string sent to the database
    Dim dbCommand As OleDbCommand               'sends the SQL string
    Dim dbConnection As OleDbConnection         'connects us to the database
    Dim dbFilePath As String = "C:\Users\KoBE\Documents\dbTest.accdb"   'file where database is located

    Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click
        'create new connection
        dbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dbFilePath)
        'the sql (instructions)
        SQL = "INSERT INTO tblTest (fldTest) VALUES ('" & TextBox1.Text & "')"
        'connect to the database
        dbConnection.Open()
        'create new command to send the sql through the connection we just initiated
        dbCommand = New OleDbCommand(SQL, dbConnection)
        'send the command
        dbCommand.ExecuteNonQuery()
        'close the connection
        dbConnection.Close()
    End Sub

    Private Sub btnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead.Click
        'sql command
        SQL = "SELECT fldTest FROM tblTest"
        'new connection
        dbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dbFilePath)
        'new command to send the sql
        dbCommand = New OleDbCommand(SQL, dbConnection)
        'data will be read via this DataAdapter
        Dim data As New OleDbDataAdapter(dbCommand)
        'creates a new data table that will store the data in memory
        Dim table As New DataTable("Test")
        'open the connection
        dbConnection.Open()
        'fill the table with the data
        data.Fill(table)
        'for each row show the value in the field 'fldTest'
        For Each row As DataRow In table.Rows
            MessageBox.Show(row.Item("fldTest"))
        Next
    End Sub
End Class

Click here to download the Sample Project and database.
Pages: 1 2