Click here to Skip to main content
15,917,565 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
protected void btnUpload_Click(object sender, EventArgs e)
{
SqlDataAdapter Da_UploadFile_id = new SqlDataAdapter("select top(1) Video_id from UploadVideo order by Video_id desc", con);
DataSet ds_UploadFile_id = new DataSet();
Da_UploadFile_id.Fill(ds_UploadFile_id);


int UploadFile_id = int.Parse(ds_UploadFile_id.Tables[0].Rows[0]["Video_id"].ToString()) + 1;
Posted

It happens when the number of rows is zero. Always check up the size of collection (count) before addressing an element by its index.

—SA
 
Share this answer
 
You need to check below:

C#
if (ds_UploadFile_id != null && ds_UploadFile_id.Tables.Count > 0 && ds_UploadFile_id.Tables[0].Rows.Count > 0)
{
    int UploadFile_id = int.Parse(ds_UploadFile_id.Tables[0].Rows[0]["Video_id"].ToString()) + 1;
}
 
Share this answer
 
v2
Comments
bhabatosh ojha 23-May-13 7:10am    
BUT when I add this then there is a build error in Uploadfile_id not found.

I will send the complete code below---
-------------------------------
protected void btnUpload_Click(object sender, EventArgs e)
{
SqlDataAdapter Da_UploadFile_id = new SqlDataAdapter("select top(1) Video_id from UploadVideo order by Video_id desc", con);
DataSet ds_UploadFile_id = new DataSet();
Da_UploadFile_id.Fill(ds_UploadFile_id);



int UploadFile_id = int.Parse(ds_UploadFile_id.Tables[0].Rows[0]["Video_id"].ToString()) + 1;


Session["test"] = UploadFile_id;
Mayur Panchal 24-May-13 1:46am    
int UploadFile_id = 0;
if (ds_UploadFile_id != null && ds_UploadFile_id.Tables.Count > 0 && ds_UploadFile_id.Tables[0].Rows.Count > 0)
{
UploadFile_id = int.Parse(ds_UploadFile_id.Tables[0].Rows[0]["Video_id"].ToString()) + 1;
}
bhabatosh ojha 24-May-13 2:08am    
This is solved with use this code..Thank sir much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900