473,397 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Code for saving NEW datatable into a database

Hi all, I am able to save, update, delete etc to data in already existing tables, but i can't seem to work out how to create and save a new table to a database. Using Visual Studio 2005, VB.

I've tried this and few other ways of coding it, but i can't seem to get it right:
__________________________________________________ ____

Public Class Form1

Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim dt As New DataTable
Dim da As New OleDb.OleDbDataAdapter
Dim dr As New DataRowAction
Dim dc As New DataColumn
Dim sql As String

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

dt.TableName = "NewTableTest1"
dt.Columns.Add(dc)
dt.Rows.Add(dr)
ds.Tables.Add(dt)

da.Update(ds)

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Users\Andrew\AFL2008ScheduleNEW.mdb"
con.Open()

sql = "SELECT * FROM AndrewsPicks"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "AFL2008ScheduleNEW")

End Sub
End Class
__________________________________________________ __

Error for this code = InvalidOperationException, refering to the code "da.Update(ds)"

Can't seem to find examples of what im looking for anywhere, any help would be appreciated.
cheers,
-Andrew
Mar 6 '08 #1
2 2826
jeffstl
432 Expert 256MB
You have to execute SQL on your database to create a new table in code like that. There is specific SQL that will do this. (CREATE syntax)

http://www.w3schools.com/sql/sql_create.asp
Mar 7 '08 #2
You have to execute SQL on your database to create a new table in code like that. There is specific SQL that will do this. (CREATE syntax)

http://www.w3schools.com/sql/sql_create.asp
I'm not familar with SQL stuff, but hopefully i'll beable to pick it up from that website, thanks alot mate, appreciate the help.
Mar 10 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: viktor9990 | last post by:
I'm using the following class to save data from database to an excel sheet. I wonder how to do so without a popup box showing up (open, save)?Thanks I want to save the exel sheet on the hard drive...
4
by: John Kandell | last post by:
Hi, I posted this in the asp.net group, but didn't get a response. Maybe someone here can help me with this... --- Would someone be able to shed some light on what is the cost of saving a...
1
by: Steven Thomas | last post by:
Can some one help me find a code snipit for saving the contents of a data set to a comma seperated file? I have created a web service in asp.net that will read the data from a AS/400 DB2...
2
by: Cary | last post by:
This may reveal my poor programming skills, but here goes... I'm building a pricing tool for my business. I'm nearing the end of the project, and I've been asked to be able to save quotes in some...
16
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and...
6
by: arun.hallan | last post by:
Hi, I have a datagrid whose datasource is a datatable which is saved to viewstate on page_load. I also have a cached string which handles what is shown on the rowfilter of the dataview of...
2
by: simonZ | last post by:
I have a dataTable in my memory(session). Can I save this table into sql dataTable in one step? Now, I'm iterating through the records and saving record by record with command object. But...
7
by: Jon | last post by:
Hi, I plan to import some data from an old DOS-based programme. The data file format that this programme produced appears to be proprietary, but I've managed to reverse engineer the format and...
5
by: jehugaleahsa | last post by:
Hello: What is the point of using a DataTable in ASP .NET? We are unsure how you can use them without 1) rebuilding them every postback, or 2) taking up precious memory. We are not sure how to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.