Hi all,
im using temporary table to hold data to display it in gridview and then from that table to database, im using cache for this process.
Problem :
sometimes one record from the table is not loading into the database. if im using break point its working.
if (Cache["Info"] != null)
{
Table = (DataTable)Cache["Info"];
Table.Rows.Add(0, this.ddl1.SelectedItem.ToString(),
this.ddl1.SelectedValue.ToString());
Table.Rows.Add(Table.Rows.Count, this.ddl2.SelectedItem.ToString(),
this.ddl2.SelectedValue.ToString());
}
foreach (DataRow dr in Table.Rows)
{
this.SetInfo(Convert.ToInt32(dr["No"]), Convert.ToString(dr["ID"]));
}
query to insert data:
INSERT INTO sample(field1, field2, field3, field4, field5, field6)
VALUES
(@field1, @field2, @field3, @field4, @field5, @field6)
try
{
if (this.sqlCon.State == ConnectionState.Closed)
this.sqlCon.Open();
this.sqlCmd = new SqlCommand("procedure_name", this.sqlCon);
this.sqlCmd.CommandType = CommandType.StoredProcedure;
this.sqlCmd.Parameters.Add(new SqlParameter("@field1", SqlDbType.VarChar));
this.sqlCmd.Parameters["@field1"].Value = value;
this.sqlCmd.Parameters.Add(new SqlParameter("@field2", SqlDbType.VarChar));
this.sqlCmd.Parameters["@field2"].Value = value;
this.sqlCmd.Parameters.Add(new SqlParameter("@field3", SqlDbType.VarChar));
this.sqlCmd.Parameters["@field3"].Value = value;
this.sqlCmd.Parameters.Add(new SqlParameter("@field4", SqlDbType.Int));
this.sqlCmd.Parameters["@field4"].Value = value;
this.sqlCmd.Parameters.Add(new SqlParameter("@field5", SqlDbType.VarChar));
this.sqlCmd.Parameters["@field5"].Value = value;
this.sqlCmd.Parameters.Add(new SqlParameter("@field6",SqlDbType.DateTime));
this.sqlCmd.Parameters["@field6"].Value = value;
this.sqlCmd.ExecuteNonQuery();
}
catch (Exception ex) { }