Hello everybody, :)
I'm trying to import an access database to mySQL by using c#, I'm using this software: MS Access to MySQL from Bullzip, and it seems to be working ok; by using c#, I can display all data from tables, using this connection:
private void btndisplayBooks_Click(object sender, EventArgs e)
{
String chainCnx = "Server=localhost; Port=3306; Database=library;Uid=root;Pwd=dark;";
MySqlConnection cnx = new MySqlConnection(chainCnx);
MySqlCommand cmd = new MySqlCommand("Select * from books;", cnx);
DataTable dt = new DataTable();
try
{
cnx.Open();
dt.Load(cmd.ExecuteReader());
dgvSearchResult.DataSource = dt; //Gridview
}
catch (Exception)
{
MessageBox.Show("ERROR");
}
finally
{
cnx.Close();
}
}
That seems to be working very well, finally I can display all data from tables, know, my problem is when I try to insert data from this GUI or a stored procedure executing this action, it seems to be not working, by using c# or MySQL Administrator and QueryBrowser, both gave me an error like this: Column count doesn't match value count at row 1
By using c#, I build this connection to insert data:
private void btnInsertarUser_Click(object sender, EventArgs e)
{
String chain2 = "Server=localhost;Port=3306;Database=library;Uid=root;Pwd=dark;";
MySqlConnection cnx2 = new MySqlConnection(chain2);
String sql = "insert into users(u_UserID, u_Name, u_lastName, u_Address, u_Tel, u_Notes, u_Email) values('"
+ txtUserID.Text +
"','"
+ txtName.Text +
"','"
+ txtLastName.Text +
"','"
+ txtTel.Text +
"','"
+ txtNotes +
"','"
+ txtEmail.Text +
"' );";
MySqlCommand cmd = new MySqlCommand(sql, cnx2);
//try
//{
cnx2.Open();
cmd.ExecuteNonQuery();
// }
// catch (Exception)
// {
// MessageBox.Show("ERROR");
// }
// finally
// {
// cnx2.Close();
// }
}
By using a Stored Procedure in QueryBrowser
CREATE DEFINER=`root`@`localhost` PROCEDURE `InsertData`()
BEGIN
insert into users(u_UserID, u_Name, u_lastName, u_Address, u_Tel, u_Notes, u_Email) values('T0120', 'F. John.', 'SMITH', 'SmallVille, '619 570 1053', 'STUDENT', 'f24@gmail.com');
END
The error is: Column count doesn't match value count at row 1
Any help would be appreciated :(