Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3235686
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:32:06+00:00 2026-05-17T17:32:06+00:00

public DataTable ExcelToDatatable_dt1 { get { foreach (GridViewRow rowItem in GridView1.Rows) { CheckBox chk;

  • 0
public DataTable ExcelToDatatable_dt1  
{
    get  
    {  
        foreach (GridViewRow rowItem in GridView1.Rows)  
        {  
            CheckBox chk;  
            // gets the Debit Reference number for each row checked  
            string productId = GridView1.DataKeys[rowItem.RowIndex].Value.ToString();  
           chk = (CheckBox)(rowItem.Cells[0].FindControl("RowChecker"));  
           if (chk.Checked)  

           {  
               string fileName = Session["fileName"].ToString();  
               //string fileName = "Collection.csv";  
               // put the file name here  
               string strSql = "SELECT * FROM [" + fileName + "] WHERE DDIREF = ["+ productId +]";  
               string strCSVConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(".\\Files\\") + ";" + "Extended Properties='text;HDR=YES;'";  


               using (FileStream filestr = new FileStream(Server.MapPath(".\\Files\\") + "\\schema.ini",  
                   FileMode.Create, FileAccess.Write))  
               {  
                   using (StreamWriter writer = new StreamWriter(filestr))  
                   {  
                       writer.WriteLine("[" + fileName + "]");  
                       writer.WriteLine("ColNameHeader=False");  
                       writer.WriteLine("Format=CSVDelimited");  
                       writer.WriteLine("DateTimeFormat=dd-MMM-yy");  

                       //Message_ltr.Text += positionList[0].ToString();  

                       for (int i = 0; i < 29; i++)  
                           //if (((positionList[i].ToString() != null) && (positionList[i].ToString() != "")) && ((nameList[i].ToString() != null) && (nameList[i].ToString() != "")))  
                           writer.WriteLine("Col" + positionList[i].ToString() + "=" + nameList[i].ToString() + " Text Width 100");  
                       //writer.WriteLine("Col2=SortCode Text Width 30");  

                       writer.Close();  
                       writer.Dispose();  
                   }  
                   filestr.Close();  
                   filestr.Dispose();  
               }  


               OleDbDataAdapter oleda = new OleDbDataAdapter(strSql, strCSVConnString);  
               DataTable dtbCSV = new DataTable();  
               oleda.Fill(dtbCSV);  

               return dtbCSV;  
           }  

        }  

        return null;// instead of null I want to return dtbCSV here  
        }  

This gives an error

“Error 45 ‘DirectDebit.Interbacs.CompanyUpload.ExcelToDatatable_dt1.get’: not all code paths return a value”.

The error is due to the return statement which is not in the correct scope. But the problem is, I want to return dtbCSV and I am not able return that within the “get” scope as dtCSV does not exist within the get context, I have no knowledge of passing the values between scopes within a return method.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T17:32:07+00:00Added an answer on May 17, 2026 at 5:32 pm

    Try putting DataTable dtbCSV = new DataTable(); before your foreach statement (and remove the other declaration).

    Edit
    Note: This will put dtbCSV in the scope of the entire get block instead of just in your if statement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class Address { public string ZipCode {get; set;} } public class Customer {
public class MyClass { public int Age; public int ID; } public void MyMethod()
public static void main(String[] args) { List<? extends Object> mylist = new ArrayList<Object>(); mylist.add(Java);
public static IList<T> LoadObjectListAll<T>() { ISession session = CheckForExistingSession(); var cfg = new NHibernate.Cfg.Configuration().Configure();
public class Test { public static void main(String[] args) { } } class Outer
public static Logger getLogger() { final Throwable t = new Throwable(); final StackTraceElement methodCaller
public class Item { ... } public class Order { public List<Item> Items ...
public enum myEnum { VAL1(10), VAL2(20), VAL3(hai) { public Object getValue() { return this.strVal;
public Int64 ReturnDifferenceA() { User[] arrayList; Int64 firstTicks; IList<User> userList; Int64 secondTicks; System.Diagnostics.Stopwatch watch;
public static IQueryable<TResult> ApplySortFilter<T, TResult>(this IQueryable<T> query, string columnName) where T : EntityObject {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.