Click here to Skip to main content
15,901,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to save new data in a database?
Posted
Comments
Mehdi Gholam 13-Oct-11 4:55am    
Edit your question and specify which database and which language.

1 solution

Assuming you are using SQL syntax of some form, you need an INSERT statement:
SQL
INSERT INTO myTable (myColumnName1, myColumnName2) VALUES ('Text for column1', 17)

If you are doing this in a .NET language then:
1) You create an instance of an SqlConnection, using your connection string
2) Open the connection using the SqlConnection.Open method
3) You create an instance of an SqlCommand, using the above SQL string, and connecting it to the SqlConnection you just opened.
4) You execute the method ExecuteNonQuery on the SqlCommand.

There are other ways, and there are refinements such as Disposing of the various objects, using Parametrized queries and so forth, but they can wait until you have the basics working.
 
Share this answer
 
Comments
Pravin Patil, Mumbai 13-Oct-11 5:25am    
5+ answer....

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