473,387 Members | 1,516 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.

How to pass stored procedure as string to another method?

Hi,

I have two methods. In one i would like to create a string from a
stored procedure to pass to the second which populates a datagrid.

private void method()
{
string sqlString = "spDataForDatagrid"; // the stored procedure
BindDataGrid(sqlString);
}

private void BindDataGrid(string sqlString)
{
// Bind data to DataGrid
}

This obviously passes the string in it's literal "spDataForDatagrid"
form. How do I reference the the actual stored procedure so the string
passed is "SELECT ..... FROM ...... etc"?

Many thanks.

Aug 8 '06 #1
3 2111
Well, you can't (robustly); the SP contents belong to the SQL-server, not
clients like C# (via ADO.Net); callers should just know it's interface
(name, params, etc); you /might/ be able to issue an sp_helptext (or similar
for other vendors), but this isn't guaranteed to return the text (encrypted,
etc).

Are you really talking about an SP? Or just a named entry e.g. in a resource
file? If you mean an SP, the normal usage is just to create a command with
the command-text of the sp-name, and command-type of sp.

Marc
Aug 8 '06 #2
...to the SQL-server...

Sorry, I should have said "to the database"... principle applies to all
backends.

Marc
Aug 8 '06 #3
Hi,

Not sure what you want. At somepoint you will have to instantiate a
SqlCommand, where you do this?
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Assimalyst" <c_******@hotmail.comwrote in message
news:11**********************@75g2000cwc.googlegro ups.com...
Hi,

I have two methods. In one i would like to create a string from a
stored procedure to pass to the second which populates a datagrid.

private void method()
{
string sqlString = "spDataForDatagrid"; // the stored procedure
BindDataGrid(sqlString);
}

private void BindDataGrid(string sqlString)
{
// Bind data to DataGrid
}

This obviously passes the string in it's literal "spDataForDatagrid"
form. How do I reference the the actual stored procedure so the string
passed is "SELECT ..... FROM ...... etc"?

Many thanks.

Aug 8 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
1
by: Raquel | last post by:
Have a question on the Stored procedure method code generated by DB2 development center for Java stored procedures. Suppose I have a requirement to return the resultset consisting of FIRSTNME,...
2
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered...
7
by: Zlatko Matić | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the...
2
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
4
by: CsharpGuy | last post by:
I took over an web app (C#) were the developer put everything in a has table then called a method to execute a stored procedure, now I'm running into some issues were if I do an update and a NULL...
7
by: Dabbler | last post by:
I'm using an ObjectDataSource with a stored procedure and am getting the following error when trying to update (ExecuteNonQuery): System.Data.SqlClient.SqlException: Procedure or Function...
7
by: Siv | last post by:
Hi, I have a stored procedure that I want to execute and then wait in a loop showing a timer whilst it completes and then carry on once I get notification that it has completed. The main reason...
4
by: scparker | last post by:
Hello, We have a stored procedure that does a basic insert of values. I am then able to retrieve the ID number created for this new record. We are currently using ASP.NET 2.0 and use N-Tier...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.