I am using C# in visual studio, trying to insert data into a column in MySql 5. I want to take the value of ampm which is am, and put it into my column ampm in my database called teleyapper.
I can connect to the data with visual studio's odbc data set and insert and retrieve the data. I can go into the mysql querey browser and insert and retrieve the data. My connection appears to work when I tried just to connect then disconnect. But for the life of me, I can't find the right syntax to insert and retieve data in my C# code. The latest syntax attempts are below. I don't catch an exception.
in addition, ampm is a string in my code, but ampm column is varchar(2). For now, I just put in two characters to insert- me
I'd appreciate any help, here is my code!
public void MysqlconnectInsert(string ampm)
{
MySql.Data.MySqlClient.MySqlConnection conn;
string myConnectionString;
myConnectionString = "server=localhost;uid=root;" +
"pwd=password;database=teleyapper;";
try
{
conn = new MySql.Data.MySqlClient.MySqlConnection();
conn.ConnectionString = myConnectionString;
conn.Open();
MessageBox.Show(ampm); // this shows the value am
MySqlCommand command = conn.CreateCommand();
// command.CommandText = "INSERT INTO `teleyapper`..`callees`(ampm) values('me')";
command.CommandText = "SELECT * FROM `teleyapper`..`callees`";
MySqlDataReader reader = command.ExecuteReader();
string retrieveampm = reader.GetString(0);
MessageBox.Show(retrieveampm); \\ this message box never shows
} //end of try
catch (MySql.Data.MySqlClient.MySqlException ex)
{
Console.WriteLine(ex.Message);
} //end of catch
I can connect to the data with visual studio's odbc data set and insert and retrieve the data. I can go into the mysql querey browser and insert and retrieve the data. My connection appears to work when I tried just to connect then disconnect. But for the life of me, I can't find the right syntax to insert and retieve data in my C# code. The latest syntax attempts are below. I don't catch an exception.
in addition, ampm is a string in my code, but ampm column is varchar(2). For now, I just put in two characters to insert- me
I'd appreciate any help, here is my code!
public void MysqlconnectInsert(string ampm)
{
MySql.Data.MySqlClient.MySqlConnection conn;
string myConnectionString;
myConnectionString = "server=localhost;uid=root;" +
"pwd=password;database=teleyapper;";
try
{
conn = new MySql.Data.MySqlClient.MySqlConnection();
conn.ConnectionString = myConnectionString;
conn.Open();
MessageBox.Show(ampm); // this shows the value am
MySqlCommand command = conn.CreateCommand();
// command.CommandText = "INSERT INTO `teleyapper`..`callees`(ampm) values('me')";
command.CommandText = "SELECT * FROM `teleyapper`..`callees`";
MySqlDataReader reader = command.ExecuteReader();
string retrieveampm = reader.GetString(0);
MessageBox.Show(retrieveampm); \\ this message box never shows
} //end of try
catch (MySql.Data.MySqlClient.MySqlException ex)
{
Console.WriteLine(ex.Message);
} //end of catch