Good afternoon community.
I am trying to log data from excel to sql using c# datagridview, but excel has a certain format.
I attach my excel of my data and see if you can guide me to be able to register them.
enter image description here
I tried to add these records in my sql server table in this way that it looks like in the attached code but it only inserts one date, and does not add all the other days in the date field and what I want is for it to insert all the dates that I have in Excel in my date field
string query = "INSERT INTO filas (item,fecha) values (@item,@fecha)";
SqlCommand cmd = new SqlCommand(query, conexion);
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@item", SqlDbType.VarChar).Value = dataGridView1.Rows[i].Cells[0].Value.ToString();
cmd.Parameters.AddWithValue("@fecha", SqlDbType.DateTime).Value = dataGridView1.Rows[i].Cells[1].Value;
cmd.ExecuteNonQuery();
New contributor
eric is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.