I'm a C#
beginner. I have 2 DataBases
. One is for when a user registers, the other is for Support section register.
Im trying to to move username
, password
, email
from one DataGridView
to the other; and then INSERT
it to the DataBase.
I'm also trying to pass the same password decryption to the other database (this way the user will need to register once and access support section with same original registered info).
But, I am getting an error:
Column 'address' cannot be null
and I am unable to think of a code to match the decryption
for password
column.
private void button3_Click(object sender, EventArgs e)
{
for (int i = 0; i < dataGridView2.Rows.Count; i++)
{
try
{
string constring = "datasource=server.server.com;port=0000;username=root;password=root;SSL Mode=None";
string query = "insert into server.user_account (username, passwd) values (@username,@passwd) ON DUPLICATE KEY UPDATE username = username,passwd=passwd;insert into server.user_email (address) values (@address) ON DUPLICATE KEY UPDATE address = address";
MySqlConnection conDataBase = new MySqlConnection(constring);
MySqlCommand cmdDataBase = new MySqlCommand(query, conDataBase);
MySqlDataReader myReader;
cmdDataBase.Parameters.AddWithValue("@username", dataGridView2.Rows[i].Cells[0].Value);
cmdDataBase.Parameters.AddWithValue("@passwd", dataGridView2.Rows[i].Cells[1].Value);
cmdDataBase.Parameters.AddWithValue("@address", dataGridView2.Rows[i].Cells[2].Value);
//cmdDataBase.Parameters.Clear();
conDataBase.Open();
myReader = cmdDataBase.ExecuteReader();
while (myReader.Read())
{
}
conDataBase.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
I've tried changing @address
to ?address
...but still getting same error.