Hi,
I am designing a purchase order form and using a GridView to input the order. I have an insert, remove row, and a submit buttons. The idea is that the user will click on insert a new row, enter data, insert a row, enter data, etc
once the user has added the items to the grid I need to reiterate through the grid and insert the data row by row into an SQL database. I can insert the current row but not sure how to reiterate through the grid using For each row, etc
Any advice is much appreciated.
Regards,
John
I am designing a purchase order form and using a GridView to input the order. I have an insert, remove row, and a submit buttons. The idea is that the user will click on insert a new row, enter data, insert a row, enter data, etc
once the user has added the items to the grid I need to reiterate through the grid and insert the data row by row into an SQL database. I can insert the current row but not sure how to reiterate through the grid using For each row, etc
Any advice is much appreciated.
Regards,
John
private void radButtonSubmitOrder_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(); dataModel dbstring = new dataModel(); conn.ConnectionString = dbstring.getDBConnString(); conn.Open(); string _insertData = "insert into Items(FormID,Item,Description,UnitsOrdered,UnitCost) values (@FormID,@Item,@Description,@UnitsOrdered,@UnitCost)"; try { SqlCommand cmd = new SqlCommand(_insertData, conn); cmd.Parameters.Add("@FormID", SqlDbType.Int); cmd.Parameters.Add("@Item", SqlDbType.Text); cmd.Parameters.Add("@Description", SqlDbType.Text); cmd.Parameters.Add("@UnitsOrdered", SqlDbType.Int); cmd.Parameters.Add("@Unitcost", SqlDbType.Money); cmd.Parameters["@FormID"].Value = "567891"; cmd.Parameters["@Item"].Value = this.radGridView1.CurrentRow.Cells[0].Value; cmd.Parameters["@Description"].Value = this.radGridView1.CurrentRow.Cells[1].Value; cmd.Parameters["@UnitCost"].Value = this.radGridView1.CurrentRow.Cells[2].Value; cmd.Parameters["@UnitsOrdered"].Value = this.radGridView1.CurrentRow.Cells[3].Value; cmd.ExecuteNonQuery(); } catch (System.Data.SqlClient.SqlException sqlException) { // Write error to Debug output stream System.Diagnostics.Debug.Write(sqlException.Message); } finally { conn.Close(); } }