Click here to Skip to main content
15,039,470 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

How to generate Sql Database Script using c# .net for insert and update at a time?

Thanks in Advance.

Ankit Agarwal
Software Engineer
Posted
Comments
W Balboos, GHB 25-Nov-13 11:09am
   
SQL database script generation has nothing to do with C# in particular.

Is your question how to generate a script or how to execute a script in C#.

What does "at a time" mean?
[no name] 26-Nov-13 2:11am
   
If(Not Existes) so insert data otherwise update the data.
Maciej Los 26-Nov-13 16:16pm
   
Not sure what you mean...
Please, be more specific and provide more details.

1 solution

You will want to Google and read up on using a DataAdapter.

Basically the process is to create a DataAdapter on a specific SQL select statement.
Then you can use a CommandBuilder to derive an insert, update, and delete sql command from your SQL select statement - or (preferably) you can pass in your own IUD SQL statements.
Then fill a data table using the DataAdapter's Fill function to read the row out of the database.
If the data table has 0 rows in it, you will need to add a new row. (This will be an insert).
Update the row in the data table however you like.

Then run the DataAdapter's Update function to update the database.

Good Luck
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900