Last active
November 10, 2016 09:50
-
-
Save arsho/fdbd3f384fd4517701b703a11b1786d3 to your computer and use it in GitHub Desktop.
C# MySQL Data insertion using mysql-connector-net-5.1.7-noinstall, Visual Studio 2015.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string connetionString = null; | |
connetionString = "server=localhost;database=device_db;uid=root;pwd=123;"; | |
using (MySqlConnection cn = new MySqlConnection(connetionString)) | |
{ | |
try | |
{ | |
string query = "INSERT INTO test_table(user_id, user_name) VALUES (?user_id,?user_name);"; | |
cn.Open(); | |
using (MySqlCommand cmd = new MySqlCommand(query, cn)) | |
{ | |
cmd.Parameters.Add("?user_id", MySqlDbType.Int32).Value = 123; | |
cmd.Parameters.Add("?user_name", MySqlDbType.VarChar).Value = "Test username"; | |
cmd.ExecuteNonQuery(); | |
} | |
} | |
catch (MySqlException ex) | |
{ | |
MessageBox.Show("Error in adding mysql row. Error: "+ex.Message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment