Add Fields to your windows form where you need to add to database.
As a example hear, I used First Name, Last Name, Age fields to add data.
In hear I added 3 labels and 3 TextBox to my form
I change the TextBox names to ,
- First Name - txtFName
- LastName - txtLName
- Age - txtAge
Double click on button & type this code hear..
string conString = "datasource=localhost;port=3306;username=root;password="; string Query = "insert into blog.empdata(fname,lName,age) values('" + this.txtFName.Text + "','"+this.txtLName.Text+"','"+this.txtAge.Text+"');"; MySqlConnection conDataBase = new MySqlConnection(conString); MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase); MySqlDataReader myReader; try { conDataBase.Open(); myReader = cmdDataBase.ExecuteReader(); MessageBox.Show("Saved"); while (myReader.Read()) { } } catch (Exception ex) { MessageBox.Show(ex.Message); }If your code is correct Message box will show the message "Saved"
That mean your data is saved in your database..
My data saved in my database
Before you try this you must have made a database named blog(something else ) and table named empdata(something else)
If you want to know how make a database please follow this link Working with MySQL Workbench
This comment has been removed by the author.
ReplyDeleteThank you for the nice and informative blog. Education helps to develop personal development, skills and capability to survive in the world.
ReplyDeletecruise ship training and placement in chennai
best visual communication insitute in chennai
Carving classes in Chennai
hotel management institute in chennai
hotel management course in chennai
hotel management College in chennai
Fashion Design Course in Chennai
Excellant post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
ReplyDeleteoracle training in chennai
oracle training in omr
oracle dba training in chennai
oracle dba training in omr
ccna training in chennai
ccna training in omr
seo training in chennai
seo training in omr
It is a great website.. The Design looks very good.. Keep working like that!. here
ReplyDelete