Я пытаюсь обновить мои строки базы данных из DataGridView
используя этот код:Обновление таблицы базы данных из DataGridView в C#
private void button2_Click(object sender, EventArgs e)
{
foreach (GridViewRow dr in dataGridView1.Rows)
{
string constring = "Data Source = localhost; port = 3306; username = root; password = 0159";
string Query = "Update TopShineDB.Table1 set Time = '" + dr.Cells[0].Text + "', CarColorNumber = '" + dr.Cells[1].Text + "', Interior = '" + dr.Cells[2].Text + "', Exterior = '" + dr.Cells[3].Text + "', CPlastic = '" + dr.Cells[4].Text + "', MPlastic = '" + dr.Cells[5].Text + "', SPlastic = '" + dr.Cells[6].Text + "', PlasticB = '" + dr.Cells[7].Text + "', WashExt = '" + dr.Cells[8].Text + "', WashEng = '" + dr.Cells[9].Text + "', WashTrunk = '" + dr.Cells[10].Text + "', WashSeats = '" + dr.Cells[11].Text + "', SeatsRmv = '" + dr.Cells[12].Text + "', SeatsFit = '" + dr.Cells[13].Text + "', Notes = '" + dr.Cells[14].Text + "', where Time = '" + dr.Cells[0].Text + "' ;";
MySqlConnection conn = new MySqlConnection(constring);
MySqlCommand command = new MySqlCommand(Query, conn);
MySqlDataReader myReader;
try
{
conn.Open();
myReader = command.ExecuteReader();
MessageBox.Show("Table Successfully Updated");
while (myReader.Read())
{
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
Но я в конечном итоге получаю эту ошибку:
{"Unable to cast object of type 'System.Windows.Forms.DataGridViewRow' to type 'System.Web.UI.WebControls.GridViewRow'."}
может быть, это помогает ... заменить Еогеасп строку с этим: 'Еогеасп (System.Web.UI.WebControls.GridViewRow dr в dataGridView1.Rows) ' –
' DataGridView' не содержит 'GridViewRows'. Сообщение об ошибке сообщает вам, что вы смешиваете объект из 2 совершенно разных пространств имен. – Plutonix
@Plutonix. Я сделал это, чтобы попытаться получить текст из таблицы dataGridView. но теперь я понимаю свою ошибку. также вы знаете, как получить текст из dataGridView? –