473,322 Members | 1,347 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,322 software developers and data experts.

Passing table name as parameter to a Stored Procedure

hi all

I have developed an asp.net application that handles college operations..
and i have created a stored procedure to delete the records under some constraints..

I have passed table name and the id which i want to delete as parameter to that stored proc..

here is the query that creates my stored procedure

create procedure usp_Delete @tablename varchar(100), @DeleteId integer as
declare @str1 nvarchar(100)
declare @str2 nvarchar(100)
set @str1 = 'delete from ' + @tablename
set @str2 = @str1 + ' where DegreeLevelId = ' + @DeleteId
execute sp_executesql @str2

The part where im calling the stored procedure is

SqlCommand cmd = new SqlCommand("usp_Delete tblDegreeLevel, ' " + id + "'", Obj.Conn);


But i couldnt concatenate the integer value with string variable..

can any one get a solution???


Looking forward for ur reply
Oct 26 '07 #1
2 1776
radcaesar
759 Expert 512MB
string strTemp="usp_Delete tblDegreeLevel, " + id +", Obj.Conn"
SqlCommand cmd = new SqlCommand(strTemp);

Is this what u talk about ?
Oct 26 '07 #2
Plater
7,872 Expert 4TB
Expand|Select|Wrap|Line Numbers
  1. SqlCommand cmd = new SqlCommand("usp_Delete tblDegreeLevel, ' " + id + "'", Obj.Conn);
  2.  
Numerical values should not be enclosed with single quotes in SQL.
Use id.ToString() to obtains it's string representation.

However, that is not the prefered way to execute stored procedures.
Expand|Select|Wrap|Line Numbers
  1. int myParam1=3;
  2.  
  3. SqlCommand sc = new SqlCommand("myStoredProcedure", dbcon);
  4. sc.CommandType = CommandType.StoredProcedure;
  5.  
  6. sc.Parameters.Add("@myParam1", SqlDbType.Int);
  7. sc.Parameters["@myParam1"].Value = myParam1;
  8. //etc
  9.  
Oct 26 '07 #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...
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...
2
by: zlatko | last post by:
There is a form in an Access Project (.adp, Access front end with SQL Server) for entering data into a table for temporary storing. Then, by clicking a botton, several action stored procedures...
6
by: dharmadam | last post by:
Is it possible to pass a column name or the order of the column name in the DB2 table table function. For example, I want to update the address of a person by passing one of the address column name...
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...
15
by: Steve | last post by:
I am trying to develop a stored procedure for an existing application that has data stored in numerous tables, each with the same set of columns. The main columns are Time and Value. There are...
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...
1
by: jkeel | last post by:
If I try to Update a record with the following code using a stored procedure I get an error: <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$...
0
by: htenay | last post by:
I need to be able to define an array in Java and pass it on to SQL stored procedure. I am new to store proc and found a lot of helpful tutorials on Google but found none that passes parameter of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.