473,387 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

passing parameters using stored procedure with where clause??

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
2 2990
truezplaya
115 100+
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
9,735 Expert Mod 8TB
You need to use the SqlCommand.Parameters property to set the variable.

-Frinny
Apr 6 '10 #3

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

Similar topics

0
by: Aaron | last post by:
The following code works fine when previewing a Crystal report using ASP, EXCEPT when it gets to a report using a SubReport and its associated parameters. The whole report just comes up blank with...
5
by: Bruno Alexandre | last post by:
Hi guys, withou using SP, I want to be able to add a Parameter to the SQL Query and retrive the Recordset so I can use the Paging property under the recorset object.... how can I do this? I'm...
3
by: WGW | last post by:
Though I am a novice to MS SQL server (2000 I believe), I can do almost! everything I need. Maybe not efficiently, but usefully. However, I have a problem -- a complex query problem... I can...
4
by: js | last post by:
I have a stored procedure named "processInventory" like the following. Depending on the passed in parameters, I would like to add a WHERE clause for "select" action. For example, if any varchar...
2
by: Bob | last post by:
I'm new to Access projects and SQL server and am not a veteran VB programmer. There's a cry for help! I'm attempting to print the current form on screen by using a command button which the user...
4
by: Mike Dinnis | last post by:
Hi, I've been working through a number of turorials to try to learn more about retrieving data from a SQL database. I think i've mastered techniques where i create a sql string in the page and...
10
by: Adis | last post by:
Asp.Net Visual Studio 2003 SQL Server. Hi, Obtaining Data Based Upon Multiple Selections From a ListBox... I have database in Sqlserver and ListBox (Multiple Selection Mode) in my Visual...
4
by: Ranginald | last post by:
Hi, I'm having trouble passing a parameter from my default.aspx page to my default2.aspx page. I have values from a query in a list box and the goal is to pass the "catID" from default.aspx...
0
by: ngoodearl | last post by:
Hi, I have upsized an access db to a sequel 2000 db. The db is used to perform a series of calculations to get a result. The user inputs the required parameters into a form and the data entered is...
2
by: zombiemasta | last post by:
Hi, I've wrote a stored procedure which expects a parameter to be passed in on the WHERE clause for channelID. The stored procedure runs fine in Navicat for MySQL when you specify the parameter...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.