How to add items to existing database thru application form
-
I currently have a dataset and would like to continually add new items to that dataset (like type a new entry in a textbox and add it with a button) and edit current items via the applications form I created. How would I go about tackling this issue? edit: This was the best base start I could come up with watching videos and going through google. Dictionary.mdf is my dataset SqlCommand cmd = new SqlCommand("insert into dictionary(word, definition) values(@word, @definition)"); cmd.Parameters.AddWithValue("@word", textBoxWordtoAdd.Text); cmd.Parameters.AddWithValue("@definition", textBoxDefinition.Text); this.Close();
-
Answer:
I think you are missing the cmd.ExecuteNonQuery(); If you were using Ms Sql Server. Then your code should look something like this: using(SqlConnection connection = new SqlConnection(ConnectionString)) { connection.Open(); string sql = "insert into dictionary(word, definition) values(@word, @definition)"; SqlCommand cmd = new SqlCommand(sql,connection); cmd.Parameters.Add("@word", SqlDbType.Varchar, 50).value = textBoxWordtoAdd.Text; cmd.Parameters.Add("@definition", SqlDbType.Varchar, 50).value = textBoxDefinition.Text; cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); } You also need to open a conneciton which I don't see in your code, but I assume you do it somewhere. Just replace the ConnectionString in the code with your own connection string.
John at Stack Overflow Visit the source
Related Q & A:
- How To Fill Green Card Application Form?Best solution by green-card.com
- How to add a list to the existing list jQuery?Best solution by designchemical.com
- How to add new view at the top of an existing view in Android?Best solution by Stack Overflow
- How to open existing database in WebSQL?Best solution by stackoverflow.com
- How to fill out a job application form?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.