The data grid in the front end interface looks like below. At least one of the color textbox should have value when the insert button is clicked. And insert a new row if there is data in any one of the color columns. And the table design in the database is like below. The status column refers to the colors in the interface. When the button is clicked, it should do a bulk insert, where it loops through every row and if there is data in the color columns, it should create at least 3 records per row.
ProductName Category Green Yellow Red
A Not ready 2015 2017 2018
B Ready 2016 2019
Table Design
ProductName Category Status Year
A Not ready 1 2015
A Not ready 2 2017
A Not ready 3 2018
B Ready 1 2016
B Ready 3 2019
What I have tried:
I tried doing for loop but did not work.
I have not done much with this.
protected void Button1_Click(object sender, EventArgs e)
{
using (SqlConnection connection = new SqlConnection())
{
connection.ConnectionString = Session[""].ToString();
foreach (GridViewRow row in wraGrid.Rows)
{
string query = "insert into [product] values (@productname,@,@Category,@Status,@Year)";
SqlCommand command = new SqlCommand(query, connection);
command.Parameters.AddWithValue("@productname", row.Cells[""].value ?? DBNull.Value);
}
}
}