4
Answers

Generate Auto Request ID and UpdateDate

Hi All,
 
I want to Import the date from Excel and show it in Grid view and also It should be inserted into SQL.
Below is my code which is importing data from Excel and show it in Gridview and inserting in SQL perfectly.
 
private void InsertData()
{
for (int i = 0; i < Dt.Rows.Count; i++)
{
DataRow row = Dt.Rows[i];
int columnCount = Dt.Columns.Count;
string[] columns = new string[columnCount];
for (int j = 0; j < columnCount; j++)
{
columns[j] = row[j].ToString();
}
conn.Open();
string sql = "INSERT INTO ParcelInf(RequestID,SubdivisionNo,ParcelNo,Region,City,Zone,CoordinateSystem,CUID,Status,Remarks,UpdateDate)";
sql += "VALUES('" + columns[0] + "','" + columns[1] + "','" + columns[2] + "','" + columns[3] + "','" + columns[4] + "','" + columns[5] + "','" + columns[6] + "','" + columns[7] + "','" + columns[8] + "','" + columns[9] + "','" + columns[10] + "')";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
conn.Close();
}
 
But I want to  create a Autogenerate RequestID (Ex:WithTodayDate) and also create a updateDate so that whenever User imports from excel it should generate Auto RequestID and UpdateDate in SQL.
 
 
 
 
Answers (4)