Good day..

I'm having problem on how to store or create a table on my database using vb.net i'm having hard time to create a table on my existing dbase

here my code;

coould you tell me what's wrong!!!


Dim ntable As OleDb.OleDbDataAdapter
Dim mtable As New DataTable
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\jesspr\Desktop\mydbase\sample.accdb"


ntable = New OleDb.OleDbDataAdapter("CREATE TABLE emp_info(" & "emp_id INTEGER NOT NULL," & "lname VARCHAR(40)," & "School_name VARCHAR(40), level varchar(40))", con)


con.Open()
ntable.Update(mtable)
MsgBox("dbase connected")

'ntable.close()
con.Dispose()
end sub


when i view my access dbase i cant see the table that was created on my code. how can i view that table?

Recommended Answers

All 3 Replies

Hi cyberdaemon, not sure about your sql statement but think you need to create an oledb command object and use ExecuteNonQuery like this:

con.Open()
            MsgBox("dbase connected")
            Dim cmd As New OleDb.OleDbCommand("CREATE TABLE emp_info(" & "emp_id INTEGER NOT NULL," & "lname VARCHAR(40)," & "School_name VARCHAR(40), level varchar(40))", con)
            cmd.ExecuteNonQuery()

Might also be an idea to put the last line in a try...catch in order to see if it throws an exception. If the table is created, you can use

ntable = New OleDb.OleDbDataAdapter("SELECT * FROM emp_info", con)
            ntable.Fill(mtable)

straight afterwards to give you upatable access to the table - to add/edit rows etc.

Hi friend...

Hope this helps...

'in GENERAL DECLARATIONS
Imports System.Data
Imports System.Data.OleDb

    Dim cn As OleDbConnection
    Dim cmd As OleDbCommand
    Dim dr As OleDbDataReader
    Dim icount As Integer
    Dim str As String

'IN BUTTON OR FORM LOAD
            Try
                cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\Inventory.mdb;Persist Security Info=False")

' & Application.StartupPath &  THIS AUTOMATICALLY ASSIGN THE PATH OF UR DATABASE(IF IT IS IN UR BIN FILE)

                cn.Open()
                str = "SELECT * FROM Tablename" 
                cmd = New OleDbCommand(str, cn)
                dr = cmd.ExecuteReader()
                    icount = cmd.ExecuteNonQuery
                    MessageBox.Show(icount)
                [CODE][/CODE]
       Catch ex As Exception
                MessageBox.Show(ex.Message & " - " & ex.Source)
                cn.Close()
            End Try
        End If

thanks for the reply my friend it helps me a lot in more advance way...
thanks..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.