473,395 Members | 1,411 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,395 software developers and data experts.

create a database table



Hello,

I know that we can use C# to connect to a database and using SQL to read
data from the tables, update tables, delete record, is there any way to
create a table or copy the structure of one table to another?

For example, I have a table dep2004, but now I want to create exactly
the same table, but it will call dep2005. I need to clear some data of
the new table, but I think I can manage it, but what I don't know how to
do it is create the table...
Can someone help me?

Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #1
4 1803
http://www.eggheadcafe.com/articles/copydatatable.asp

--
2004 and 2005 Microsoft MVP C#
Robbe Morris
http://www.robbemorris.com
http://www.masterado.net

"Claudia Fong" <cd********@yahoo.co.uk> wrote in message
news:ee*************@TK2MSFTNGP15.phx.gbl...


Hello,

I know that we can use C# to connect to a database and using SQL to read
data from the tables, update tables, delete record, is there any way to
create a table or copy the structure of one table to another?

For example, I have a table dep2004, but now I want to create exactly
the same table, but it will call dep2005. I need to clear some data of
the new table, but I think I can manage it, but what I don't know how to
do it is create the table...
Can someone help me?

Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #2
Assuming that you have the authority to create tables in the database:

SELECT
*
INTO
dep2005
FROM
dep2004
WHERE
1 = 0

is a way to create an empty copy of a table.

"Claudia Fong" <cd********@yahoo.co.uk> wrote in message
news:ee*************@TK2MSFTNGP15.phx.gbl...


Hello,

I know that we can use C# to connect to a database and using SQL to read
data from the tables, update tables, delete record, is there any way to
create a table or copy the structure of one table to another?

For example, I have a table dep2004, but now I want to create exactly
the same table, but it will call dep2005. I need to clear some data of
the new table, but I think I can manage it, but what I don't know how to
do it is create the table...
Can someone help me?

Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #3

First of all thanks Brendan.

It works, but I still have one little problem:

In my old table DEP2004, I have one field that the property allow zero
length is YES, but after creating the new table DEP2005, this property
change to NO. It means it won't allow zero lenght.. How can I change
this property in C#?

My database is stored in Access.

Do you know how should I do?
Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #4
We used ADOX in ASP to get this type of task done but I'm sorry to say I
have no experience using ADOX with ASP.NET yet. Try this search term...

Google: "adox"+" asp.net"

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/

"Claudia Fong" <cd********@yahoo.co.uk> wrote in message
news:O5*************@TK2MSFTNGP12.phx.gbl...

First of all thanks Brendan.

It works, but I still have one little problem:

In my old table DEP2004, I have one field that the property allow zero
length is YES, but after creating the new table DEP2005, this property
change to NO. It means it won't allow zero lenght.. How can I change
this property in C#?

My database is stored in Access.

Do you know how should I do?
Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Robin Tucker | last post by:
I have some code that dynamically creates a database (name is @FullName) and then creates a table within that database. Is it possible to wrap these things into a transaction such that if any one...
9
by: Albretch | last post by:
.. I am trying to create a database in a MS Access DB via JDBC drivers. I have tried both sun.jdbc.odbc.JdbcOdbcDriver and ids.sql.IDSDriver From some reason both drivers Exceptions tell me...
2
by: Jacob | last post by:
A simple question: I've read a couple of things that indicates I can create a new table in my database using some SQL command. Is this correct? I would like to load a database into a DataSet,...
4
by: John T. Howard | last post by:
Can you issue commands from VB.Net to create and delete databases? I would like to create, delete, and copy MSAccess tables and/or databases from code. Can this be done? Can you show, or point...
9
by: Peter | last post by:
Hello£¬everyone, My program will collect a testing machine's data ,save the data and deal with the data everyday. I want to use vb.net to create database, add and delete tables or modify the...
27
by: max | last post by:
Hello, I am a newbye, and I'm trying to write a simple application. I have five tables with three columns; all tables are identical; I need to change some data in the first table and let VB...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
15
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to...
3
by: DeanL | last post by:
Hi guys, Does anyone know of a way to create multiple tables using information stored in one table? I have a table with 4 columns (TableName, ColumnName, DataType, DataSize) and wanted to know...
10
by: AAaron123 | last post by:
I want to create a database with one table on the host. I can't user SQL Server Management Studio to do it so I guess I have to do it programmatically. I have in mind that in the session start...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.