By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,408 Members | 1,840 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,408 IT Pros & Developers. It's quick & easy.

passing parameters using stored procedure with where clause??

P: 13
i have created this function with a parameter offset and i want to access the database using stored procedure but the code and stored procedure i have written below is not working...what is the right way to do it??

Expand|Select|Wrap|Line Numbers
  1. public bool isoffsetexist(int offset)
  2.     {
  3.         conn.Open();
  4.  
  5.         SqlCommand cmd = new SqlCommand();
  6.         cmd.Connection = conn;
  7.         cmd.CommandType = CommandType.StoredProcedure;
  8.         cmd.CommandText = "sp_offset1";
  9.         SqlDataReader dr = cmd.ExecuteReader();
  10.  
  11.         int i = 0;
  12.         while (dr.Read())
  13.         {
  14.             i++;
  15.         }
  16.         if (i == 1)
  17.         {
  18.             conn.Close();
  19.             return true;
  20.         }
  21.         else
  22.         {
  23.             conn.Close();
  24.             return false;
  25.         }
  26.     }
  27.  
my stored procedure "sp_offset1" is

Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE [dbo].[sp_offset1]
  2. @offset numeric,
  3. @appname varchar(20),
  4. @os varchar(20)
  5.  AS
  6. select * from tb_offset
  7.  where @offset=" + offset + "
  8.  
Apr 6 '10 #1
Share this Question
Share on Google+
2 Replies


100+
P: 115
http://www.c-sharpcorner.com/UploadF...eSPwithDP.aspx

I'm not entirely sure this is what you are looking for but have a look towards the end of the page. It has a little sample of adding parameters

truez
Apr 6 '10 #2

Frinavale
Expert Mod 5K+
P: 9,731
You need to use the SqlCommand.Parameters property to set the variable.

-Frinny
Apr 6 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.