Also, as stated before "using (SqlDataAdapter" is useless, because a DataAdapter opens and closes it's own connection. It seems particularly useless here, because you aren't using it at all.
Don't define that command inside the insert. There's no reason to keep recreating it:
using (SqlCommand command = new SqlCommand()) {
command.CommandText = "INSERT INTO tb_plane_attributes(FK_plane_id, FK_attribute_id, value) VALUES(@FK_plane_id, @FK_attribute_id, @value)";
// ar you sure, isn't this int?
command.Parameters.AddWithValue("@FK_plane_id", FK_plane_id);
command.Parameters.Add("@FK_attribute_id", SqlDbType.Int);
command.Parameters.Add("@value", SqlDbType.Int;
foreach (DataGridViewRow row in GrdAllAttributes.Rows) {
command.Parameters["@FK_attribute_id"]= row.Cells["@FK_attribute_id"].Value;
command.Parameters["@value"] = row.Cells["dd"].Value;
command.ExecuteNonQuery();
}
}

New Topic/Question
Reply





MultiQuote



|