0

I am writing a method which will call a stored procedure. This stored Procedure will return a dataset which contains an attributes. I need to change the value of one particular attribute. My code is something like this.

try
        {               
            cmdPendingStatus.CommandType = CommandType.StoredProcedure;
            SqlDataReader pendingStatusList;
            List<string> lstPendingRequestId = new List<string>();
            try
            {
                conn.Open();
                pendingStatusList = cmdPendingStatus.ExecuteReader();
                if (pendingStatusList.HasRows)
                {
                    while (pendingStatusList.Read())
                    {
                        lstPendingRequestId.Add(pendingStatusList.GetString(0));
                    }

                }
            }
1
  • After this point i am stuck. After I add the Sqldatareader to list, Next what I want to do is reach to the element at Row 1 column 4. Please help me. Commented Feb 3, 2016 at 6:12

4 Answers 4

1

cmdPendingStatus.CommandType=CommandType.StoredProcedure;
SqlDataReader pendingStatusList;
List<string> lstPendingRequestId = new List<string>();

try
{
  conn.Open();
  pendingStatusList = cmdPendingStatus.ExecuteReader();
  if (pendingStatusList.HasRows)
  {
    while (pendingStatusList.Read())
    {
      if(condition here)
      {
        lstPendingRequestId.add("NEW VALUE")
      }
      else
      {
        lstPendingRequestId.Add(pendingStatusList.GetString(0));
      }
    }
  }
}
hope this will help you

Sign up to request clarification or add additional context in comments.

Comments

0

Column name to be specified within pendingStatusList["ColumnName"]

  try
            {
                conn.Open();
                pendingStatusList = cmdPendingStatus.ExecuteReader();
                if (pendingStatusList.HasRows)
                {
                    while (pendingStatusList.Read())
                    {
                        lstPendingRequestId.Add(pendingStatusList["ColumnName"]);
                    }

                }
            }

7 Comments

No what I need to do is retrieve the whole table in the list and from there on I need to change the specified row column entry and then insert into another table.
u need to store entire table in an object ? or u need to store as table
you can use the following code to store into a table DataTable datable1 = new DataTable(); datatable1.Load(cmdPendingStatus.ExecuteReader());
I have another stored procedure to store the values returned by passing the values to the stored procedure one by one in another table.
Is the result of 1st stored procedure has multiple columns ?
|
0

You can't change an attribute in ExecuteReader but you can read a value like this:

var value = Reader[1];

You can always change the value of var and write another stored procedure to save changes if that is what you want to do.

Comments

0
try
{
     DataSet dsStatusPending = new DataSet();
     StoredProcedure cmdPendingStatus = new StoredProcedure();
     cmdPendingStatus.ProcName = "sp_Name";
     dsStatusPending = DbManager.ExecuteDataSet(cmdPendingStatus);
     if (dsStatusPending.Tables[0].Rows.Count > 0)
     {
          foreach (DataRow rowToInsert in dsStatusPending.Tables[0].Rows)
          {                  
              if (rowToInsert["ColumnName"] != System.DBNull.Value && rowToInsert["ColumnName"].ToString().ToUpper() == "I")
              {
                   //User Defined Code Goes Here
              }
           }
      }

This is how I got to the specific column.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.