Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot return datatable
    text
    copied!<pre><code>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 &lt; 29; i++) //if (((positionList[i].ToString() != null) &amp;&amp; (positionList[i].ToString() != "")) &amp;&amp; ((nameList[i].ToString() != null) &amp;&amp; (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 } </code></pre> <p>This gives an error</p> <blockquote> <p>"Error 45 'DirectDebit.Interbacs.CompanyUpload.ExcelToDatatable_dt1.get': not all code paths return a value".</p> </blockquote> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload