kumartyr

kumartyr

  • NA
  • 55
  • 28.1k

How to save data from gridview to database

May 26 2016 8:02 AM
Hi
 
I used the link http://www.c-sharpcorner.com/UploadFile/8c19e8/dynamically-adding-and-deleting-rows-in-gridview-and-saving/
 
but getting ORA-00911: Invalid character
 
Below the code i tried
 
 
private void InsertRecords(StringCollection sc)
{
try
{
StringBuilder sb = new StringBuilder(string.Empty);
string[] splitItems = null;
foreach (string item in sc)
{
const string sqlStatement = "INSERT into MOM_DETAILS (SERIALNO,MEETINGID,DETAILSOFDISCUSSIONS,ACTION,ACTIONOWNER,REMARKS,STATUS,FEEDBACK,SDATE) VALUES";
if (item.Contains(","))
{
splitItems = item.Split(",".ToCharArray());
sb.AppendFormat("{0}('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}'); ", sqlStatement, splitItems[0], splitItems[1], splitItems[2], splitItems[3], splitItems[4], splitItems[5], splitItems[6], splitItems[7], splitItems[8]);
}
}
using (OracleConnection connection = new OracleConnection(strConnection))
{
connection.Open();
using (OracleCommand cmd = new OracleCommand(sb.ToString(), connection))
{
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
}
ResultLabel.Text = "Records successfully saved!";
}
catch (Exception er)
{
ResultLabel.Text = er.ToString();
}
}
public int ct;
public string Tdate = DateTime.Today.ToString("d-MMM-yy");
protected void SaveAllButton_Click(object sender, EventArgs e)
{
try
{
int rowIndex = 0;
StringCollection sc = new StringCollection();
if (ViewState["CurrentTable"] != null)
{
DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
ct = dtCurrentTable.Rows.Count;
if (dtCurrentTable.Rows.Count > 0)
{
for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
{
TextBox box1 = (TextBox)MeetingDetailGridView.Rows[rowIndex].Cells[1].FindControl("MIDTextBox");
TextBox box2 = (TextBox)MeetingDetailGridView.Rows[rowIndex].Cells[2].FindControl("DODTextBox");
TextBox box3 = (TextBox)MeetingDetailGridView.Rows[rowIndex].Cells[3].FindControl("ActionTextBox");
TextBox box4 = (TextBox)MeetingDetailGridView.Rows[rowIndex].Cells[4].FindControl("ActionOwnerTextBox");
TextBox box5 = (TextBox)MeetingDetailGridView.Rows[rowIndex].Cells[5].FindControl("RemarksTextBox");
TextBox box6 = (TextBox)MeetingDetailGridView.Rows[rowIndex].Cells[6].FindControl("StatusTextBox");
TextBox box7 = (TextBox)MeetingDetailGridView.Rows[rowIndex].Cells[7].FindControl("FeedbackTextBox");
sc.Add(string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8}", ct, box1.Text, box2.Text, box3.Text, box4.Text, box5.Text, box6.Text, box7.Text, Tdate));
rowIndex++;
}
InsertRecords(sc);
}
}
//SetPreviousData();
}
catch (Exception rt)
{
rt.ToString();
}
}
 
 
 
 
 

Answers (4)