473,382 Members | 1,648 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.

sql parameter

example below can we get a parameter by name or have to use the indexOf

SqlCommand cmd = new SqlCommand("proc_ERRORLOG_INSERT", oConn);

cmd.CommandType = CommandType.StoredProcedure;

SqlParameter param = new SqlParameter();

cmd.Parameters.Add("@Fileid", SqlDbType.Int).Value=99999;

cmd.Parameters.Add("@ErrorMessage", SqlDbType.VarChar).Value="Service Failed
on APP Server1";

cmd.Parameters.Add("@Retvalue",
SqlDbType.Int).Direction=ParameterDirection.Output ;

int iret = cmd.ExecuteNonQuery();

Console.WriteLine("return value "+iret.ToString()); //iRet is Rows
Affected

Console.WriteLine(cmd.Parameters.IndexOf("@Retvalu e")); // Proc Return
Number (value)

console.Read();

how can i get the @retvalue by name , Not by its index position in the
collection

TIA MJ


Apr 11 '07 #1
5 5047
MikeJ,

You should be able to do:

SqlParameter = cmd.Parameters["@retvalue"];

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"MikeJ" <ve***********@yahoo.comwrote in message
news:eQ*****************@newssvr21.news.prodigy.ne t...
example below can we get a parameter by name or have to use the indexOf

SqlCommand cmd = new SqlCommand("proc_ERRORLOG_INSERT", oConn);

cmd.CommandType = CommandType.StoredProcedure;

SqlParameter param = new SqlParameter();

cmd.Parameters.Add("@Fileid", SqlDbType.Int).Value=99999;

cmd.Parameters.Add("@ErrorMessage", SqlDbType.VarChar).Value="Service
Failed on APP Server1";

cmd.Parameters.Add("@Retvalue",
SqlDbType.Int).Direction=ParameterDirection.Output ;

int iret = cmd.ExecuteNonQuery();

Console.WriteLine("return value "+iret.ToString()); //iRet is Rows
Affected

Console.WriteLine(cmd.Parameters.IndexOf("@Retvalu e")); // Proc Return
Number (value)

console.Read();

how can i get the @retvalue by name , Not by its index position in the
collection

TIA MJ


Apr 11 '07 #2
"MikeJ" <ve***********@yahoo.comwrote in message
news:eQ*****************@newssvr21.news.prodigy.ne t...
how can i get the @retvalue by name , Not by its index position in the
collection
cmd.Parameters["@retvalue"] should work.
Apr 11 '07 #3
Thank you
MJ

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:%2****************@TK2MSFTNGP03.phx.gbl...
MikeJ,

You should be able to do:

SqlParameter = cmd.Parameters["@retvalue"];

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"MikeJ" <ve***********@yahoo.comwrote in message
news:eQ*****************@newssvr21.news.prodigy.ne t...
>example below can we get a parameter by name or have to use the indexOf

SqlCommand cmd = new SqlCommand("proc_ERRORLOG_INSERT", oConn);

cmd.CommandType = CommandType.StoredProcedure;

SqlParameter param = new SqlParameter();

cmd.Parameters.Add("@Fileid", SqlDbType.Int).Value=99999;

cmd.Parameters.Add("@ErrorMessage", SqlDbType.VarChar).Value="Service
Failed on APP Server1";

cmd.Parameters.Add("@Retvalue",
SqlDbType.Int).Direction=ParameterDirection.Outpu t;

int iret = cmd.ExecuteNonQuery();

Console.WriteLine("return value "+iret.ToString()); //iRet is Rows
Affected

Console.WriteLine(cmd.Parameters.IndexOf("@Retval ue")); // Proc Return
Number (value)

console.Read();

how can i get the @retvalue by name , Not by its index position in the
collection

TIA MJ



Apr 11 '07 #4
here is a piece of my code...the parameter fileid is not returning
SqlCommand Cmd = new SqlCommand("oa_SERVICE_OA2_getFileToProcess",
oConnect);

Cmd.CommandType = CommandType.StoredProcedure;

Cmd.CommandTimeout = 600;

Cmd.Parameters.Add("Statusid", SqlDbType.Int).Value = 123; //Direction =
ParameterDirection.Input;

Cmd.Parameters.Add("FormTypeid", SqlDbType.Int).Value = 2;//Direction =
ParameterDirection.Input;

Cmd.Parameters.Add("SetStatusIdTo", SqlDbType.Int).Value = 139; //Direction
= ParameterDirection.Input;

Cmd.Parameters.Add("FileId", SqlDbType.Int).Direction =
ParameterDirection.Output;

Cmd.Parameters.Add("FilePath", SqlDbType.VarChar,244).Direction =
ParameterDirection.Output;

Cmd.Parameters.Add("ReturnCode", SqlDbType.Int).Direction =
ParameterDirection.ReturnValue;

int iRet = Cmd.ExecuteNonQuery();

Console.WriteLine(Cmd.Parameters["ReturnCode"].Value); //shows
correct value

Console.WriteLine(Cmd.Parameters["Fileid"].Value); //shows
empty

Console.WriteLine(Cmd.Parameters["FilePath"].Value); //Empty

Console.WriteLine("Ret {0}", iRet.ToString()); // Shows
Correct Value

Console.Read();
Tia
MJ


"Alberto Poblacion" <ea******************************@poblacion.orgwro te
in message news:%2****************@TK2MSFTNGP06.phx.gbl...
"MikeJ" <ve***********@yahoo.comwrote in message
news:eQ*****************@newssvr21.news.prodigy.ne t...
>how can i get the @retvalue by name , Not by its index position in the
collection

cmd.Parameters["@retvalue"] should work.


Apr 11 '07 #5
"MikeJ" <ve***********@yahoo.comwrote in message
news:T3*****************@newssvr27.news.prodigy.ne t...
here is a piece of my code...the parameter fileid is not returning
[...]
Cmd.Parameters.Add("FileId", SqlDbType.Int).Direction = [...]
Console.WriteLine(Cmd.Parameters["Fileid"].Value);
//shows empty
I suspect a casing problem: you are creating the parameter as "FileId"
(uppercase "I") and then looking for "Fileid" (lowercase "i").
Apr 12 '07 #6

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

Similar topics

4
by: Dan | last post by:
I've run into an interesting problem, and seemed to have stumped 3 newsgroups and 2 other forums. For some reason when I try to insert a record into a SQL table that has a Text column, the...
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: John A Grandy | last post by:
Is there something special in XML about the name "Parameter" ... I am not able to XPATH query for nodes named "Parameter" <Root> <Category CategoryID="1"> <Elements> <Element...
2
by: PK | last post by:
Hi, I have an application that opens a Crystal report document and passes in a value to a parameter in the report (pointing to an Oracle DB). However, if I want to pass a "null" value to retrieve...
7
by: Richard Grant | last post by:
Hi. In c/C++ i can pass the address of a subroutine to another subroutine as an actual parameter How do I do that in VB .NET What should be the syntax for a parameter to receive the address of a...
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...
16
by: hzmonte | last post by:
Correct me if I am wrong, declaring formal parameters of functions as const, if they should not be/is not changed, has 2 benefits; 1. It tells the program that calls this function that the...
3
by: Ken Cox [Microsoft MVP] | last post by:
I've been going around and around on this one. I can't believe that it is "by design" as Microsoft says. Here's the situation: In *declarative* syntax, I'm trying to create a default datetime...
20
by: exipnakias | last post by:
Hello Guys. In a form I created a listbox which looks up the values of a table. I want: 1) ..to create a query where a parameter will be needed in order to be loaded. But I do not want to...
5
by: Trevisc | last post by:
Happy Thursday Everyone, I am trying to create a parameter that is one long varchar but that will be used in a SQL statement IN function: //string queryString = GetCurrentTitles(); //Below is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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...

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.