Andyloveprogram
9/10/2017 - 9:36 AM

SPToDatatable.cs

 using System.Collections.Specialized;
 using System.Configuration;
 using System.Data.SqlClient;
 using System.Data.OleDb;
 public static DataTable GetAllPendingValidationApprover(string claimNo, string approvalLevel)
        {
                 try
                    {
                        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["AdidasDBConnectionString"].ConnectionString);

                        SqlCommand cmd = new SqlCommand("GetAllPendingApprover", conn);
                        cmd.CommandType = System.Data.CommandType.StoredProcedure;
                        cmd.Parameters.Add("@ClaimNo", SqlDbType.NVarChar, 50).Value = claimNo;
                        cmd.Parameters.Add("@ApprovalLevel", SqlDbType.NVarChar, 50).Value = approvalLevel;
                        conn.Open();
                        DataTable dt = new DataTable();
                        using (var da = new SqlDataAdapter(cmd))
                        {
                            cmd.CommandType = CommandType.StoredProcedure;
                            da.Fill(dt);
                        }

                        return dt; 
                    }
                    catch (SqlException ex)
                    {
                        return null;
                        // handle error
                    }
                    catch (Exception ex)
                    {
                        return null;
                        // handle error
                    }
                   
               for (int i = 0; i < dt.Rows.Count; i++)
            {
                string item = dt.Rows[i][5].ToString();
                //do something
                
            }

                
        }