Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi guys
i have a stored procedure in sql server 2008 which works fine when i execute it in server explorer but when i can't read any data when i call it from my program,here is my code:
 
DataTable result = null;
            try
            {
                using (con)
                {
                    using (SqlCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.CommandText = "CheckSite";
                        cmd.Parameters.Add(new SqlParameter("@site", site));
                        using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                        {
                            result = new DataTable();
                            da.Fill(result);
                            if (result.Rows.Count>0)
                            {
                                
                                return 1;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //Pokemon exception handling
            }
            return 0;
 
what did i do wrong?the database contains 2rows!but my code allways returns 0 (as not finding any)
 
Here it is my store procedure:
 
ALTER PROCEDURE dbo.CheckSite
	@site nvarchar(150)
AS
	select sitename from Saved where sitename = @site
	RETURN
Posted 15-Sep-12 6:47am
Edited 15-Sep-12 7:29am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I think it is a problem in this string:
if (result.Rows.Count>0)
Try to set following code in your procedure:
SET NOCOUNT OFF;
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

try this:
  
.....
....
...
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
 DataSet result = new DataSet();
 dataset.Tables.Add("aaa");
 da.Fill(dataset, "aaa");
 if (result.Tables[0].Rows.Count>0)
 {
 
    return 1;
 }
}
........
.......
  Permalink  
v2
Comments
Arash Khangaldi at 15-Sep-12 13:37pm
   
result.Rows.Count makes error :'System.Data.DataSet' does not contain a definition for 'Rows' and no extension method 'Rows' accepting a first argument of type 'System.Data.DataSet' could be found =
Wes Aday at 15-Sep-12 13:42pm
   
Because tables have rows, datasets do not.
Kuthuparakkal at 15-Sep-12 23:09pm
   
updated soln check

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

  Print Answers RSS
0 Dnyaneshwar@Pune 604
1 thatraja 370
2 OriginalGriff 319
3 Sergey Alexandrovich Kryukov 241
4 Gihan Liyanage 194
0 OriginalGriff 737
1 Dnyaneshwar@Pune 604
2 Kornfeld Eliyahu Peter 505
3 Sergey Alexandrovich Kryukov 372
4 thatraja 370


Advertise | Privacy | Mobile
Web01 | 2.8.140902.1 | Last Updated 15 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100