Click here to Skip to main content
14,698,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i have the following codes in C# which is to retrieve rows of records from stored procedure:

using (conn = new SqlConnection(GeminiConnString))
{
    using (command = new SqlCommand("dbo.CZ_InsertIntoProjectManagementOutstandingExcel", conn))
    {
            conn.Open();
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.AddWithValue("@startDate", StartDate);
            command.Parameters.AddWithValue("@endDate", EndDate);

            command.ExecuteNonQuery();

        //Sto-Pro Details
        SqlDataAdapter da = new SqlDataAdapter(command);
        DataSet ds = new DataSet();
        da.Fill(ds);
        dt = ds.Tables[0];

        conn.Close();
    }
}


Then after that i want to append a value which is the numbering e.g. 1 into the first row of record and 2 to the second row of record. I have the below codes:

//the lastColValue is the last value i retrieve from a column name 'No'. Then the '1' above or any other numbering will follow after the last value. E.g. lastColValue is 10 then newColValue would be 11
string lastColvalue = ExcelDt.Rows[ExcelDt.Rows.Count - 1]["No"].ToString();
int newColValue = Convert.ToInt32(lastColvalue);
for (int i = 0; i < dt.Rows.Count; i++)
{
    newColValue = newColValue + 1;
    //add here
}
Posted

1 solution

Hi,

Please not use this code for updating one column, id for every Row.

Use below syntax in your query as an extra column and fetch in datatable then it will come automatically. It will increase your performance and reduce time.

Row_Number() over(order by (Select 0)) as SrNo
   
Comments
Jamie888 11-Jul-14 3:50am
   
where should i put this line in?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900