Как вставить данные gridview в базу данных
я получаю ошибку входная строка была не в правильном формате
Что я уже пробовал:
try { if (ViewState["dtAck"] != null) dtAck = ViewState["dtAck"] as DataTable; if (dtAck == null) dtAck = AddPanchayats(); string strFile = string.Empty; if (dtAck.Rows.Count > 0) { //Saving the data DataSet dataSetPanchayats = new DataSet(); dataSetPanchayats.Tables.Add(dtAck); string fName = string.Empty; foreach (GridViewRow gvr in gvhouseholddetials.Rows) { TextBox i = (TextBox)gvr.FindControl("txtNOOFCARDSDISTRIBUTED"); CheckBox checkBox = (CheckBox)gvr.FindControl("checkBox"); int totalJC = Convert.ToInt32(gvhouseholddetials.Rows[gvr.RowIndex].Cells[4].Text.Trim()); if (Convert.ToInt32(i.Text) > totalJC && checkBox.Checked) { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Warning", "alert('Please enter proper value of Total no of cards distributed');", true); //gvhouseholddetials.Rows[gvr.RowIndex].Focus(); TextBox txtNOOFCARDSDISTRIBUTED = gvhouseholddetials.Rows[gvr.RowIndex].FindControl("txtNOOFCARDSDISTRIBUTED") as TextBox; txtNOOFCARDSDISTRIBUTED.Focus(); txtNOOFCARDSDISTRIBUTED.Enabled = true; checkBox.Checked = false; return; } TextBox d = (TextBox)gvr.FindControl("txtD"); string txtdate = Convert.ToString(d.Text); if (txtdate == "") { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Warning", "alert('Please select distributed date');", true); gvhouseholddetials.Rows[gvr.RowIndex].Focus(); gvhouseholddetials.Rows[gvr.RowIndex].Cells[5].Focus(); gvhouseholddetials.Rows[gvr.RowIndex].Cells[5].Enabled = true; TextBox txtTD = gvhouseholddetials.Rows[gvr.RowIndex].FindControl("txtD") as TextBox; txtTD.Enabled = true; checkBox.Checked = false; return; } if (txtdate != "" && checkBox.Checked) { DateTime myDate = DateTime.ParseExact(txtdate, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture); DateTime startDate = DateTime.ParseExact("01/01/2017", "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture); if (myDate > DateTime.Today || myDate < startDate) { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Warning", "alert('Please enter proper date' );", true); gvhouseholddetials.Rows[gvr.RowIndex].Focus(); gvhouseholddetials.Rows[gvr.RowIndex].Cells[5].Focus(); gvhouseholddetials.Rows[gvr.RowIndex].Cells[5].Enabled = true; TextBox txtTD = gvhouseholddetials.Rows[gvr.RowIndex].FindControl("txtD") as TextBox; txtTD.Enabled = true; checkBox.Checked = false; return; } } } string msg = new GenericBO().GetString(new object[] { dataSetPanchayats.GetXml(), objPortalUser.PCCInfoCode, objPortalUser.UserName, null }, "JobCard_Printing.SaveAcknowledgedJobCard_APO"); if (msg == "SUCCESS") { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Warning", "alert('Data saved successfully');", true); ViewState.Remove("dtAck"); gvhouseholddetials.DataBind(); ViewState.Remove("bindGrid"); //btnSubmit.Visible = false; }