473,836 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sql parameter problem

Hello

I have this:

public SqlParameter GetParameter(st ring sqlparam)

{
SqlParameter param = cmd.Parameters. Add(sqlparam);

param.Direction = ParameterDirect ion.Output;

return param;

}

and I get:

Cannot implicitly convert type 'int' to 'System.Data.Sq lClient.SqlPara meter'

problem is that I dont "want" to be needed to specify datatype of the
parameter, if I check "6 of 6" in that yellow hint-box, as I get it, I'm
able to just pass the parameter-name.

or what's needed to do?

TIA
/Lasse



Nov 16 '05 #1
5 6403
Richard,

I cant pass the value since that's what im trying to retrieve.

/Lasse
"Richard Blewett [DevelopMentor]" <ri******@devel op.com> wrote in message
news:%2******** *******@tk2msft ngp13.phx.gbl.. .
The problem is you are calling the following overload of Add

int Add( object o );

and you are trying to assign it to a SqlParameter reference - hence the error message.
if you can supply the value as well you can call this overload

SqlParameter Add(string name, object value);

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft. com/microsoft.publi c.dotnet.langua ges.csharp/<uq************ **@TK2MSFTNGP14 .phx.gbl>
Hello

I have this:

public SqlParameter GetParameter(st ring sqlparam)

{
SqlParameter param = cmd.Parameters. Add(sqlparam);

param.Direction = ParameterDirect ion.Output;

return param;

}

and I get:

Cannot implicitly convert type 'int' to 'System.Data.Sq lClient.SqlPara meter'
problem is that I dont "want" to be needed to specify datatype of the
parameter, if I check "6 of 6" in that yellow hint-box, as I get it, I'm
able to just pass the parameter-name.

or what's needed to do?

TIA
/Lasse


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.768 / Virus Database: 515 - Release Date: 22/09/2004

[microsoft.publi c.dotnet.langua ges.csharp]

Nov 16 '05 #2
public SqlParameter GetParameter(st ring sqlparam)
{
SqlParameter param = new SqlParameter();
param.Parameter Name = sqlParam;
param.Direction = ParameterDirect ion.Output;
cmd.Parameters. Add(param);
return param;
}

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
Lasse Edsvik wrote:
Hello

I have this:

public SqlParameter GetParameter(st ring sqlparam)

{
SqlParameter param = cmd.Parameters. Add(sqlparam);

param.Direction = ParameterDirect ion.Output;

return param;

}

and I get:

Cannot implicitly convert type 'int' to 'System.Data.Sq lClient.SqlPara meter'

problem is that I dont "want" to be needed to specify datatype of the
parameter, if I check "6 of 6" in that yellow hint-box, as I get it, I'm
able to just pass the parameter-name.

or what's needed to do?

TIA
/Lasse


Nov 16 '05 #3
OK in that case you'll need to change your code as follows:

SqlParameter GetParameter(Sq lCommand cmd, string pname)
{
SqlParameter p = new SqlParameter();
p.ParameterName = pname;
p.Direction = ParameterDirect ion.Output;
cmd.Parameters. Add(p);
return p;
}

btw: when are you doing to set the param type for the out param?

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft. com/microsoft.publi c.dotnet.langua ges.csharp/<eq************ **@TK2MSFTNGP09 .phx.gbl>

Richard,

I cant pass the value since that's what im trying to retrieve.

/Lasse
"Richard Blewett [DevelopMentor]" <ri******@devel op.com> wrote in message
news:%2******** *******@tk2msft ngp13.phx.gbl.. .
The problem is you are calling the following overload of Add

int Add( object o );

and you are trying to assign it to a SqlParameter reference - hence the error message.
if you can supply the value as well you can call this overload

SqlParameter Add(string name, object value);

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft. com/microsoft.publi c.dotnet.langua ges.csharp/<uq************ **@TK2MSFTNGP14 .phx.gbl>
Hello

I have this:

public SqlParameter GetParameter(st ring sqlparam)

{
SqlParameter param = cmd.Parameters. Add(sqlparam);

param.Direction = ParameterDirect ion.Output;

return param;

}

and I get:

Cannot implicitly convert type 'int' to 'System.Data.Sq lClient.SqlPara meter'
problem is that I dont "want" to be needed to specify datatype of the
parameter, if I check "6 of 6" in that yellow hint-box, as I get it, I'm
able to just pass the parameter-name.

or what's needed to do?

TIA
/Lasse


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.768 / Virus Database: 515 - Release Date: 22/09/2004

[microsoft.publi c.dotnet.langua ges.csharp]


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.769 / Virus Database: 516 - Release Date: 24/09/2004

[microsoft.publi c.dotnet.langua ges.csharp]
Nov 16 '05 #4
Richard,

hmm, not sure, what happens if i dont?

btw, do i "need" to pass the "SqlCommand cmd"?

thx
/Lasse
"Richard Blewett [DevelopMentor]" <ri******@devel op.com> wrote in message
news:%2******** **********@TK2M SFTNGP10.phx.gb l...
OK in that case you'll need to change your code as follows:

SqlParameter GetParameter(Sq lCommand cmd, string pname)
{
SqlParameter p = new SqlParameter();
p.ParameterName = pname;
p.Direction = ParameterDirect ion.Output;
cmd.Parameters. Add(p);
return p;
}

btw: when are you doing to set the param type for the out param?

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft. com/microsoft.publi c.dotnet.langua ges.csharp/<eq************ **@TK2MSFTNGP09 .phx.gbl>
Richard,

I cant pass the value since that's what im trying to retrieve.

/Lasse
"Richard Blewett [DevelopMentor]" <ri******@devel op.com> wrote in message
news:%2******** *******@tk2msft ngp13.phx.gbl.. .
> The problem is you are calling the following overload of Add
>
> int Add( object o );
>
> and you are trying to assign it to a SqlParameter reference - hence the

error message.
>
> if you can supply the value as well you can call this overload
>
> SqlParameter Add(string name, object value);
>
> Regards
>
> Richard Blewett - DevelopMentor
> http://staff.develop.com/richardb/weblog
>
>

nntp://news.microsoft. com/microsoft.publi c.dotnet.langua ges.csharp/<uq************ **@TK2MSFTNGP14 .phx.gbl>
>
> Hello
>
> I have this:
>
> public SqlParameter GetParameter(st ring sqlparam)
>
> {
>
>
> SqlParameter param = cmd.Parameters. Add(sqlparam);
>
> param.Direction = ParameterDirect ion.Output;
>
> return param;
>
> }
>
>
>
> and I get:
>
> Cannot implicitly convert type 'int' to

'System.Data.Sq lClient.SqlPara meter'
>
>
>
> problem is that I dont "want" to be needed to specify datatype of the
> parameter, if I check "6 of 6" in that yellow hint-box, as I get it, I'm > able to just pass the parameter-name.
>
> or what's needed to do?
>
> TIA
> /Lasse
>
>
>
>
>
>
>
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.768 / Virus Database: 515 - Release Date: 22/09/2004
>
>
>
> [microsoft.publi c.dotnet.langua ges.csharp]


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.769 / Virus Database: 516 - Release Date: 24/09/2004

[microsoft.publi c.dotnet.langua ges.csharp]

Nov 16 '05 #5
SqlParameter defaults its SqlDbType to NVarChar. So unless you are only going to return NVarChar types and you preset the size, this isn't going to work.

Also, if you don't pass the SqlCommand in how are you going to call cmd.Parameters. Add, do you have it as a member variable?

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft. com/microsoft.publi c.dotnet.langua ges.csharp/<#Y************ **@TK2MSFTNGP10 .phx.gbl>

Richard,

hmm, not sure, what happens if i dont?

btw, do i "need" to pass the "SqlCommand cmd"?

thx
/Lasse
"Richard Blewett [DevelopMentor]" <ri******@devel op.com> wrote in message
news:%2******** **********@TK2M SFTNGP10.phx.gb l...
OK in that case you'll need to change your code as follows:

SqlParameter GetParameter(Sq lCommand cmd, string pname)
{
SqlParameter p = new SqlParameter();
p.ParameterName = pname;
p.Direction = ParameterDirect ion.Output;
cmd.Parameters. Add(p);
return p;
}

btw: when are you doing to set the param type for the out param?

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft. com/microsoft.publi c.dotnet.langua ges.csharp/<eq************ **@TK2MSFTNGP09 .phx.gbl>
Richard,

I cant pass the value since that's what im trying to retrieve.

/Lasse
"Richard Blewett [DevelopMentor]" <ri******@devel op.com> wrote in message
news:%2******** *******@tk2msft ngp13.phx.gbl.. .
The problem is you are calling the following overload of Add

int Add( object o );

and you are trying to assign it to a SqlParameter reference - hence the

error message.

if you can supply the value as well you can call this overload

SqlParameter Add(string name, object value);

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft. com/microsoft.publi c.dotnet.langua ges.csharp/<uq************ **@TK2MSFTNGP14 .phx.gbl>

Hello

I have this:

public SqlParameter GetParameter(st ring sqlparam)

{
SqlParameter param = cmd.Parameters. Add(sqlparam);

param.Direction = ParameterDirect ion.Output;

return param;

}

and I get:

Cannot implicitly convert type 'int' to

'System.Data.Sq lClient.SqlPara meter'

problem is that I dont "want" to be needed to specify datatype of the
parameter, if I check "6 of 6" in that yellow hint-box, as I get it, I'm able to just pass the parameter-name.

or what's needed to do?

TIA
/Lasse


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.768 / Virus Database: 515 - Release Date: 22/09/2004

[microsoft.publi c.dotnet.langua ges.csharp]


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.769 / Virus Database: 516 - Release Date: 24/09/2004

[microsoft.publi c.dotnet.langua ges.csharp]


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.769 / Virus Database: 516 - Release Date: 24/09/2004

[microsoft.publi c.dotnet.langua ges.csharp]
Nov 16 '05 #6

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

Similar topics

4
3850
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 returned autogenerated Identity is wrong (on the VB side). This only occurs if the length of the value inserted for the text column is >= 8002. I've included a simple example below.
3
16951
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 create a parameter query in a stored procedure, but how do I use the result set of a parameter query in a select query (in the same or another sp)? In short, if a select query contains a result table that is generated as a parameter query, how do I...
4
2738
by: wkaras | last post by:
I would like to propose the following changes to the C++ Standard, the goal of which are to provide an improved ability to specify the constraints on type parameters to templates. Let me say from the start that my knowledge of compiler implementation is very limited. Therefore, my suggestions may have to be rejected because they are difficult or impossible to implement. The proposal is based on the concept of "type similarity". Type...
2
2767
by: Siegfried Weiss | last post by:
Hi guys, i give up finding a solution by reading or by trial & error. Hope, YOU can help me! (Sorry for my rather long posting.) Stroustrup says, that templates could be declared with - type parameter, e.g. template<class T> - parameters with *simple* types like int, e.g. template<int size> - template parameter, e.g. template< template<class> class A > the latter beeing a type specifier, not an instance of A.
8
13184
by: Dave Veeneman | last post by:
Can I pass a method pass one of its out parameters to another method? C# is telling me I can't. Let's say I have two methods, FooManager and FooWorker. FooManager is part of a class that acts as a coordinator for several other classes. FooManager basically passes its parameters, including an output parameter 'x', on to FooWorker, a worker method in another class. FooWorker does the actual work and assigns to x. When FooWorker is done, it...
0
2189
by: Billie Boy | last post by:
Hi to all. I’m new here and am coming to you from Melbourne Australia. So a big HELLO 2 ALL. Now I am encountering an annoying problem in the SQL builder of the copy of VB.6 that I am using at home. My problem is that it’s driving me NUTS NUTS NUTS. I am connected to a data connection within my computer that accesses tables & views from a MS Access file.
8
2707
by: Alec MacLean | last post by:
Hi, I'm using the DAAB Ent Lib (Jan 2006) for .NET 2.0, with VS 2005 Pro. My project is a Web app project (using the WAP add in). Background: I'm creating a survey system for our company, for which invites will target selected personnel among our customers via email. Each email will provide a custom hyperlink for each respondent using a SQL generated GUID value in the querystring. The GUID will be checked for validity before the user...
4
8064
by: =?Utf-8?B?QmlsbEF0V29yaw==?= | last post by:
Hi, We recently converted a 1.1 project to 2.0 and this included a webservice which accepted XML for one of the parameters. Since converting to 2.0 I am getting the following message: --- A potentially dangerous Request.Form value was detected from the client (myparam="<root><blah...."). --- The fix used for ASPX pages is to include the @Page directive with
5
5309
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 for Test string queryString = "45322,32222,33344,55555"; dataset catalogDS = new dataset();
8
4640
by: DanicaDear | last post by:
I have something interesting...looking to see if anyone else has came across this. I have a query with parameter and and the query works beautifully every time. However, when I use the wizard to build a report, at the end of the wizard the report opens beautifully, asks for the 2 parameters, and displays results. Beautiful. Then, after closing the report and re-opening, the report promts me for a third, unwanted parameter. ...
0
9656
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10819
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10526
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10567
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10237
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7771
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6972
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5811
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4000
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.