Not all code paths return a value
-
private DataTable AddNewRowToGrid() { int rowIndex = 0; if (ViewState\["CurrentTable"\] != null) { DataTable dtCurrentTable = (DataTable)ViewState\["CurrentTable"\]; DataRow drCurrentRow = null; if (dtCurrentTable.Rows.Count > 0) { for (int i = 1; i <= dtCurrentTable.Rows.Count; i++) { //extract the TextBox values drCurrentRow = dtCurrentTable.NewRow(); dtCurrentTable.Rows\[i - 1\]\["EffectFrom"\] = ((TextBox)mdlpopupGrid.Rows\[rowIndex\].Cells\[1\].FindControl("txtEffectFrom")).Text; dtCurrentTable.Rows\[i - 1\]\["EffectivePercentage"\] = ((TextBox)mdlpopupGrid.Rows\[rowIndex\].Cells\[2\].FindControl("txtEffectivePercentage")).Text; dtCurrentTable.Rows\[i - 1\]\["Grade\_Salary"\] = ((TextBox)mdlpopupGrid.Rows\[rowIndex\].Cells\[3\].FindControl("txtGradeSalary")).Text; rowIndex++; } dtCurrentTable.Rows.Add(drCurrentRow); ViewState\["CurrentTable"\] = dtCurrentTable; return dtCurrentTable; } } }
This code gives me the Fallowing Error: Not all code paths return a value plss Help !!
-
private DataTable AddNewRowToGrid() { int rowIndex = 0; if (ViewState\["CurrentTable"\] != null) { DataTable dtCurrentTable = (DataTable)ViewState\["CurrentTable"\]; DataRow drCurrentRow = null; if (dtCurrentTable.Rows.Count > 0) { for (int i = 1; i <= dtCurrentTable.Rows.Count; i++) { //extract the TextBox values drCurrentRow = dtCurrentTable.NewRow(); dtCurrentTable.Rows\[i - 1\]\["EffectFrom"\] = ((TextBox)mdlpopupGrid.Rows\[rowIndex\].Cells\[1\].FindControl("txtEffectFrom")).Text; dtCurrentTable.Rows\[i - 1\]\["EffectivePercentage"\] = ((TextBox)mdlpopupGrid.Rows\[rowIndex\].Cells\[2\].FindControl("txtEffectivePercentage")).Text; dtCurrentTable.Rows\[i - 1\]\["Grade\_Salary"\] = ((TextBox)mdlpopupGrid.Rows\[rowIndex\].Cells\[3\].FindControl("txtGradeSalary")).Text; rowIndex++; } dtCurrentTable.Rows.Add(drCurrentRow); ViewState\["CurrentTable"\] = dtCurrentTable; return dtCurrentTable; } } }
This code gives me the Fallowing Error: Not all code paths return a value plss Help !!
insert return null; before the last }
-
private DataTable AddNewRowToGrid() { int rowIndex = 0; if (ViewState\["CurrentTable"\] != null) { DataTable dtCurrentTable = (DataTable)ViewState\["CurrentTable"\]; DataRow drCurrentRow = null; if (dtCurrentTable.Rows.Count > 0) { for (int i = 1; i <= dtCurrentTable.Rows.Count; i++) { //extract the TextBox values drCurrentRow = dtCurrentTable.NewRow(); dtCurrentTable.Rows\[i - 1\]\["EffectFrom"\] = ((TextBox)mdlpopupGrid.Rows\[rowIndex\].Cells\[1\].FindControl("txtEffectFrom")).Text; dtCurrentTable.Rows\[i - 1\]\["EffectivePercentage"\] = ((TextBox)mdlpopupGrid.Rows\[rowIndex\].Cells\[2\].FindControl("txtEffectivePercentage")).Text; dtCurrentTable.Rows\[i - 1\]\["Grade\_Salary"\] = ((TextBox)mdlpopupGrid.Rows\[rowIndex\].Cells\[3\].FindControl("txtGradeSalary")).Text; rowIndex++; } dtCurrentTable.Rows.Add(drCurrentRow); ViewState\["CurrentTable"\] = dtCurrentTable; return dtCurrentTable; } } }
This code gives me the Fallowing Error: Not all code paths return a value plss Help !!
The reason it's given you this message is because you have the condition to test if the
ViewState
is not null. What happens ifViewState["CurrentTable"]
is null? (You have a similar issue ifdtCurrentTable.Rows.Count == 0
. To fix this, return an emptyDataTable
from the method (most style guides recommend not returning null).*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
-
insert return null; before the last }
Can SARIGÜL wrote:
insert return null; before the last }
not working actually I want this Function result to be used as Datatable to fill a Gridview. return null will work
-
private DataTable AddNewRowToGrid() { int rowIndex = 0; if (ViewState\["CurrentTable"\] != null) { DataTable dtCurrentTable = (DataTable)ViewState\["CurrentTable"\]; DataRow drCurrentRow = null; if (dtCurrentTable.Rows.Count > 0) { for (int i = 1; i <= dtCurrentTable.Rows.Count; i++) { //extract the TextBox values drCurrentRow = dtCurrentTable.NewRow(); dtCurrentTable.Rows\[i - 1\]\["EffectFrom"\] = ((TextBox)mdlpopupGrid.Rows\[rowIndex\].Cells\[1\].FindControl("txtEffectFrom")).Text; dtCurrentTable.Rows\[i - 1\]\["EffectivePercentage"\] = ((TextBox)mdlpopupGrid.Rows\[rowIndex\].Cells\[2\].FindControl("txtEffectivePercentage")).Text; dtCurrentTable.Rows\[i - 1\]\["Grade\_Salary"\] = ((TextBox)mdlpopupGrid.Rows\[rowIndex\].Cells\[3\].FindControl("txtGradeSalary")).Text; rowIndex++; } dtCurrentTable.Rows.Add(drCurrentRow); ViewState\["CurrentTable"\] = dtCurrentTable; return dtCurrentTable; } } }
This code gives me the Fallowing Error: Not all code paths return a value plss Help !!
Add: else { return null; } before last '}'.