C# data export to excel - error
Hi all, hope in your help.
I am creating a C# 2010 Web application.
I have researched and test this and this should work...but I get an error and I can't get past this problem...my code below.
I would greatly appreciate any help you can give me in working this problem
CS0161: '_Default.GetData(System.Data.Odbc.OdbcCommand)': not all code paths return a value
private DataTable GetData(OdbcCommand cmd)
{
DataTable dt = new DataTable();
OdbcDataAdapter sda = new OdbcDataAdapter();
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
try
{
con.Open();
sda.SelectCommand = cmd;
sda.Fill(dt);
if (dt.Rows.Count > 0)
{
return dt;
}
else
{
string strScript = "<script>" + "alert('Not found!.');";
strScript += "window.location='default.aspx';";
strScript += "</script>";
Page.ClientScript.RegisterStartupScript(this.GetType(), "Startup", strScript);
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
sda.Dispose();
con.Dispose();
}
}