|
-
Jun 20th, 2003, 03:27 PM
#1
Thread Starter
Addicted Member
Insert a datatable into d database
O.K. i have extracted info from one database and have placed the info in a datatable. I want to take that datatable and place the info in it in a different database that does not contain that table. i wnat to create a new table in the database and have it equal the datatable i have extracted.
How can i do this? Is it doable? If so how....
Thanks!!!
-
Jun 21st, 2003, 10:46 AM
#2
Lively Member
I haven't done it myself, but Balena's text demonstrates it in some detail. Here's enough to get you started, I think.
Sub Create EmployeesTable()
Dim dtEmp as New DataTable("Employees")
dtEmp.MinimumCapacity = 100
dtEmp.CaseSensetive = False, etc etc
' create columns
Dim dcFName as New DataColumn("FirstName", GetType(String))
dtEmp.Columns.Add(dcFname)
' another way
dtEmp.Columns.Add("City", GetType(String)).MaxLength = 20
' Create an ID
Dim dcEmpId as New DataColumn("EmpID", GetType(Integer))
dcEmpID.AutoIncrement = True
dcEmpID.AutoIncrementSeed = 1
dcEmpID.AllowDBNull = False, etc, etc
dtEmp.Columns.Add(dcEmp)
' Make it a primary key
Dim pkCols() as DataColumn = {deEmpId}
dtEmp.PrimaryKey = pkCols
' add the table to a dataset
ds.Tables.Add(dtEmp)
there you go
-
Jun 22nd, 2003, 01:35 PM
#3
Thread Starter
Addicted Member
THat is not exactly what i meant, I know how to do that but i do not know how to put the datatable that i have created into an existing database.
for example i created a table with 3 columns and i want to store the newly created table in a database say...mydb.mdb and i want to save the datatable as a new table in the mydb.mdb database how could i do that?
Thanks for your help
-
Jun 22nd, 2003, 02:19 PM
#4
Lively Member
-
Jun 24th, 2003, 08:30 PM
#5
Thread Starter
Addicted Member
would this be possible?
Use sql to create a table witht the exact name of the datatable i have. Name the colums in the database table the same as the columns i have in the datatable. Then just use the .update command on a dataset object.
Would this work if it were done right?
-
Jun 25th, 2003, 07:54 PM
#6
Thread Starter
Addicted Member
-
Jun 26th, 2003, 07:06 PM
#7
Lively Member
Originally posted by Buy2easy.com
would this be possible?
Use sql to create a table witht the exact name of the datatable i have. Name the colums in the database table the same as the columns i have in the datatable. Then just use the .update command on a dataset object.
Would this work if it were done right?
I assume so, providing you have the proper InsertCommand. Why not try and see?
-
Jun 29th, 2003, 03:17 PM
#8
Thread Starter
Addicted Member
hello, i am in the process of adding the table and i have created a table in the new database with the columns the same name as the ones i want to insert but i am having trouble with one thing i am making the columns a text type in the database but columns are not a text type in the datatable. i tried to change each of the columns to a datatype string like
whateverthecolumniscalled.datatype = system.type.gettype("system.string")
but that is saying that a string type can not be found ar something.
how can i change the properties of the datatable so that they are of a string type or a text type?
thanks!
-
Jun 30th, 2003, 11:43 AM
#9
Lively Member
I posted some code in the C# forum that shows how to do this entire process, including setting the data types of the columns in both the dataset and the table. It's pretty close to VB. Note the code I am referring to is near the bottom of the thread.
http://www.vbforums.com/showthread.p...hreadid=251282
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|