Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating a new table int the database using datatable

Status
Not open for further replies.

erxi9

Programmer
Jul 8, 2003
10
0
0
IL
Hi all !
i need to create a new datatable in the memory
and to update the sql server
how can i do it ?
 
Here is what you should do:
- The user used to connect to the DB must have privileges to create objects (tables)
- Connect to the DB by creating an SqlConnection object and providing a Connection string
-Open the connection.
- create SqlDataAdapter, SqlCommand objects to execute the CREATE TABLE ... by calling ExecuteNoQuery() on the SqlCommand object.
- if done successfull then call Fill() on the DataAdapter to create a DataTable object by sending the SQL command text : "Select * from thattable";
-Update the DataTable object e.g. add rows, modify, delete
- create a SqlCommandBuilder object using the above SqlDataAdapter object and call the Update() method to put back (commit) the DataTable in the data source.
-If you still to continue to update the DataTable object after this step then call AcceptChanges() on the DataTable object.
- Cleanup (Dispose()) no nedeed objects
Use try-catch block to capture any error on each above steps and take actions accordingly.
-obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top