Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there anyone here with a good knowledge working with Visual Basic + Access DB?
#1
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?
Reply
#2
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
[Image: t5BWm.png]
Reply
#3
Yeah. I heard Kobe is a great coder. I would message him if I were you.
[Image: rara.png]
Reply
#4
Alright thanks guys, I'll PM this KoBe dude. ;) <3
Reply
#5
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.
[Image: burninglove4.png]
Reply
#6
(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/
Reply
#7
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.
[Image: burninglove4.png]
Reply
#8
(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.
Reply
#9
alright guys thanks for taking the time to help me. I'll be waiting ;) <3
Reply
#10
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How To make an advanced Operating System in Visual Basic 2010 ? Mohamed Samir 9 12,595 01-15-2013, 09:30 PM
Last Post: Resistance
  [Visual Basic] FTP Uploader [Tutorial] Coding Support 6 3,042 08-12-2012, 12:36 AM
Last Post: Kenneth
  Visual Studio Bill Nye The Science Guy 1 1,043 03-19-2012, 09:08 AM
Last Post: BreShiE
  Visual Basic Guide - Buttons Death Demise 9 5,350 03-09-2012, 06:46 PM
Last Post: BreShiE
  Visual Basic Guides, Tutorials, Web Resources, and E-books Compilation simply_mark 1 1,802 11-16-2011, 06:30 AM
Last Post: TalishHF

Forum Jump:


Users browsing this thread: 2 Guest(s)