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.
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.

Khan Abrar AhmedRank #778 · 3K reputationPosted Jul 20, 2014, 6:50 AM EDT
1. Create store procedure to insert the record in store procedure for auto generate request id use below code.
ex: select isnull(Max(RequestID),0)+1 from ParcelInf;
and for the UpdateDate feild use the getdate() function of sql.
2. Next call the sproc to insert the data.
Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 20, 2014, 9:01 PM EDT
hi,
you can insert updated data using Getdate() method of SQL. Regarding auto generated RequestId, can you please share the business logic and also possible scenarios?
Azarudeen Ibn Liyakath Ali30 reputationPosted Jul 20, 2014, 11:14 PM EDT
I am new to Dotnet and I do not know how to use store procedure in the above code.
Is there any sample I can get?
Khan Abrar AhmedRank #778 · 3K reputationPosted Jul 21, 2014, 12:08 AM EDT
http://www.c-sharpcorner.com/uploadfile/jitendra1987/sql-server-stored-procedure-with-C-Sharp-net/
http://www.codeproject.com/Questions/224585/how-to-call-stored-procedure-in-asp-net-csharp-cod