sangeetha k

sangeetha k

  • NA
  • 207
  • 49.2k

Cannot find table 0.

Sep 15 2017 2:16 AM
I am trying to auto generate id in the webpage it gives me cannot find table o(Index out of Range Exception)
Tell me where i am wrong and what i have to do 
 
 
My databaselayer
public int generateid()
{
int id = 0;
DataSet ds = new DataSet();
string constring = null;
SqlConnection conn = null;
try
{
constring = ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString;
conn = new SqlConnection(constring);
conn.Open();
SqlCommand cmd = new SqlCommand("spAutoGeneratecustomerId1", conn);
cmd.CommandType = CommandType.StoredProcedure;
// SqldataAdapter da = new SqldataAdapter(cmd);
id = Convert.ToInt32(ds.Tables[0].Rows[0]["Customer_id"].ToString());
}
catch (Exception ex)
{
Console.WriteLine("Error" + ex.Message);
}
return id;
}
 #business logic layer
 
public int getId()
{
int id;
id=dal.generateid();
return id;
}
 #code behind
 
public partial class Test : System.Web.UI.Page
{
Business bal = new Business();
protected void Page_Load(object sender, EventArgs e)
{
txtId.Text = bal.getId().ToString();
}
 

Answers (2)