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

SqlDataAdapter, Stored Procedure, how to add parameter?

Hello, from the code below, how do I add/send a parameter to the stored
procedure?

SqlConnection conn = null;
conn = new
SqlConnection(System.Configuration.ConfigurationMa nager.ConnectionStrings["ConnectionString"].ConnectionString);
conn.Open();
SqlDataAdapter daProjects = new SqlDataAdapter("dbo.getProjectFiles",
conn);

DataSet ds = new DataSet();
daProjects.Fill(ds);

Jan 15 '07 #1
3 12693
I think something like this:

d.SelectCommand.Parameters.Add(new
System.Data.SqlClient.SqlParameter("paramname","pa ram"));

There are 7 overrides for the constructor on SqlParameter, I've just
picked the simple one. You may also have to add a SqlCommand to the
SelectCommand first.

dawson wrote:
Hello, from the code below, how do I add/send a parameter to the stored
procedure?

SqlConnection conn = null;
conn = new
SqlConnection(System.Configuration.ConfigurationMa nager.ConnectionStrings["ConnectionString"].ConnectionString);
conn.Open();
SqlDataAdapter daProjects = new SqlDataAdapter("dbo.getProjectFiles",
conn);

DataSet ds = new DataSet();
daProjects.Fill(ds);
Jan 15 '07 #2
I know how to do it this way ... which works ...

conn = new
SqlConnection(System.Configuration.ConfigurationMa nager.ConnectionStrings["ConnectionString"].ConnectionString);
conn.Open();

// 1. create a command object identifying
// the stored procedure
SqlCommand cmd = new SqlCommand(
"dbo.insertProjectFile", conn);

// 2. set the command object so it knows
// to execute a stored procedure
cmd.CommandType = CommandType.StoredProcedure;

// 3. add parameter to command, which
// will be passed to the stored procedure
cmd.Parameters.Add(new SqlParameter("@StrFileName", StrFileName));

cmd.ExecuteNonQuery();
But I can't figure out how to do it with the sqladapator as it doesn't
have the cmd.ExecuteNonQuery(); at the end, but just binds to the
dataset with fill!
DeveloperX wrote:
I think something like this:

d.SelectCommand.Parameters.Add(new
System.Data.SqlClient.SqlParameter("paramname","pa ram"));

There are 7 overrides for the constructor on SqlParameter, I've just
picked the simple one. You may also have to add a SqlCommand to the
SelectCommand first.

dawson wrote:
Hello, from the code below, how do I add/send a parameter to the stored
procedure?

SqlConnection conn = null;
conn = new
SqlConnection(System.Configuration.ConfigurationMa nager.ConnectionStrings["ConnectionString"].ConnectionString);
conn.Open();
SqlDataAdapter daProjects = new SqlDataAdapter("dbo.getProjectFiles",
conn);

DataSet ds = new DataSet();
daProjects.Fill(ds);
Jan 15 '07 #3
http://www.c-sharpcorner.com/UploadF...eSPwithDP.aspx

dawson wrote:
I know how to do it this way ... which works ...

conn = new
SqlConnection(System.Configuration.ConfigurationMa nager.ConnectionStrings["ConnectionString"].ConnectionString);
conn.Open();

// 1. create a command object identifying
// the stored procedure
SqlCommand cmd = new SqlCommand(
"dbo.insertProjectFile", conn);

// 2. set the command object so it knows
// to execute a stored procedure
cmd.CommandType = CommandType.StoredProcedure;

// 3. add parameter to command, which
// will be passed to the stored procedure
cmd.Parameters.Add(new SqlParameter("@StrFileName", StrFileName));

cmd.ExecuteNonQuery();
But I can't figure out how to do it with the sqladapator as it doesn't
have the cmd.ExecuteNonQuery(); at the end, but just binds to the
dataset with fill!
DeveloperX wrote:
I think something like this:

d.SelectCommand.Parameters.Add(new
System.Data.SqlClient.SqlParameter("paramname","pa ram"));

There are 7 overrides for the constructor on SqlParameter, I've just
picked the simple one. You may also have to add a SqlCommand to the
SelectCommand first.

dawson wrote:
Hello, from the code below, how do I add/send a parameter to the stored
procedure?
>
SqlConnection conn = null;
conn = new
SqlConnection(System.Configuration.ConfigurationMa nager.ConnectionStrings["ConnectionString"].ConnectionString);
conn.Open();
SqlDataAdapter daProjects = new SqlDataAdapter("dbo.getProjectFiles",
conn);
>
DataSet ds = new DataSet();
daProjects.Fill(ds);
Jan 15 '07 #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...
2
by: RitaG | last post by:
Hi. Is it possible to run a Stored Procedure that takes 1 parameter using the SQLDataAdapter. I'm currently using the SQLCommand with the SQLDataReader to do this but would like to use a...
4
by: Rhino | last post by:
Is it possible for a Java Stored Procedure in DB2 V7.2 (Windows) to pass a Throwable back to the calling program as an OUT parameter? If yes, what datatype should I use when registering the...
3
by: W Akthar | last post by:
I am trying to use SqlDataAdapter to execute a Stored Procedure. The Stored Procedure is as follows CREATE Procedure SP_GetAddressesFromContactID @ID int AS SELECT b.StreetAddress1,
7
by: Matt Jensen | last post by:
Howdy Fairly simple question I think, I presume the answer is no it can't be reused for 2 *SELECT* statements, but just hoping for clarification. Just asking in the interests of trying to minimise...
1
by: hlam | last post by:
I am configuring an SqlDataAdapter using a stored procedure (which uses UNIONS and a Temporary Table) in Visual Studio.Net My stored procedure consists of: SELECT ... INTO #tbltemporary ...
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...
2
by: jed | last post by:
I have created this example in sqlexpress ALTER PROCEDURE . @annualtax FLOAT AS BEGIN SELECT begin1,end1,deductedamount,pecentageextra FROM tax
2
by: suganya | last post by:
Hi I have to bind the DropDownList box with ID field hidden using SQLDataAdapter. For that I have given the coding as protected void Page_Load(object sender, EventArgs e) { ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
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
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...

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.