user6592730 user6592730 - 3 months ago 15
ASP.NET (C#) Question

How to check a value in dataset is empty or not?

I have a fileupload option in my project. It inclueds a query which returns a dataset. It works fine. But now i want to check whether the returning dataset is is empty or the same value i passed as a parameter to the query. Here is my back end code.

.cs code

if ((FileUpload1.HasFile))//&& (ext == ".pdf")
{
ds = db.checkExistingPDF(fileName);
if (dbFileName != fileName)
{
this.FileUpload1.SaveAs(Path.Combine(svrPath, fileName + ".pdf"));
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", " alert('Successfully uploaded');", true);
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", " confirm ('Appeal is availbale for the this competition') ; ", true);
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", " confirm ('Error') ; ", true);
}


Here is my query

public DataSet checkExistingPDF(string fileName)
{
string strQuery = @"IF EXISTS (SELECT * FROM APPEAL_MASTER WHERE Attachment_upload = '"+ fileName +"')";

return SqlHelper.ExecuteDataset(strConnStringAppeal, CommandType.Text, strQuery);
}

Answer

To check dataset is empty or not You have to check null and tables count.

Dataset ds=checkExistingPDF("filename");
if(ds != null && ds.Tables.count > 0)
{
 // your code
}
Comments