473,498 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SqlHelper.ExecuteScalar

Hi,

I have a problem with SqlHelper.ExecuteScalar ...

When I try to execute SqlHelper.ExecuteScalar I get this message:
"System.InvalidCastException: Object must implement IConvertible.".

Help ...

Thanx, Neven

----------------------
SqlParameter[] arrSqlParam = null;
arrSqlParam =
SqlHelperParameterCache.GetSpParameterSet(DB.getCo nnectiongString(),
"GetFullUserName");
arrSqlParam[0].Value = strUserName;

strFullUserName = Utility.SqlHelper.ExecuteScalar(DB.getConnectiongS tring(),
"GetFullUserName", arrSqlParam);

------------------------
CREATE PROCEDURE GetFullUserName
@strUserName nvarchar(50),
@strUserNameFull nvarchar(100) OUT
AS

SET @strUserNameFull = (SELECT ime + ' ' + prezime FROM tblUsers WHERE
[tblUsers].[user_name] = @strUserName)
GO

Nov 19 '05 #1
7 11986
ExecuteScalar returns a Object type..you should cast this object to a string
like so:

strFullUserName = (string)
Utility.SqlHelper.ExecuteScalar(DB.getConnectiongS tring(),
"GetFullUserName", arrSqlParam);

"Neven Klofutar" wrote:
Hi,

I have a problem with SqlHelper.ExecuteScalar ...

When I try to execute SqlHelper.ExecuteScalar I get this message:
"System.InvalidCastException: Object must implement IConvertible.".

Help ...

Thanx, Neven

----------------------
SqlParameter[] arrSqlParam = null;
arrSqlParam =
SqlHelperParameterCache.GetSpParameterSet(DB.getCo nnectiongString(),
"GetFullUserName");
arrSqlParam[0].Value = strUserName;

strFullUserName = Utility.SqlHelper.ExecuteScalar(DB.getConnectiongS tring(),
"GetFullUserName", arrSqlParam);

------------------------
CREATE PROCEDURE GetFullUserName
@strUserName nvarchar(50),
@strUserNameFull nvarchar(100) OUT
AS

SET @strUserNameFull = (SELECT ime + ' ' + prezime FROM tblUsers WHERE
[tblUsers].[user_name] = @strUserName)
GO

Nov 19 '05 #2
It's not that, I still get an error, I also tried this:

strFullUserName =
Convert.ToString(Utility.SqlHelper.ExecuteScalar(U tility.DB.getConnectiongSt
ring(), "GetFullUserName", arrSqlParam));
"Tampa .NET Koder" <Ta***********@discussions.microsoft.com> wrote in
message news:C3**********************************@microsof t.com...
ExecuteScalar returns a Object type..you should cast this object to a string like so:

strFullUserName = (string)
Utility.SqlHelper.ExecuteScalar(DB.getConnectiongS tring(),
"GetFullUserName", arrSqlParam);

"Neven Klofutar" wrote:
Hi,

I have a problem with SqlHelper.ExecuteScalar ...

When I try to execute SqlHelper.ExecuteScalar I get this message:
"System.InvalidCastException: Object must implement IConvertible.".

Help ...

Thanx, Neven

----------------------
SqlParameter[] arrSqlParam = null;
arrSqlParam =
SqlHelperParameterCache.GetSpParameterSet(DB.getCo nnectiongString(),
"GetFullUserName");
arrSqlParam[0].Value = strUserName;

strFullUserName = Utility.SqlHelper.ExecuteScalar(DB.getConnectiongS tring(), "GetFullUserName", arrSqlParam);

------------------------
CREATE PROCEDURE GetFullUserName
@strUserName nvarchar(50),
@strUserNameFull nvarchar(100) OUT
AS

SET @strUserNameFull = (SELECT ime + ' ' + prezime FROM tblUsers WHERE
[tblUsers].[user_name] = @strUserName)
GO

Nov 19 '05 #3
Utility.SqlHelper ... is not an error, I put it in my library ...

Neven

strFullUserName =
Convert.ToString(Utility.SqlHelper.ExecuteScalar(U tility.DB.getConnectiongSt ring(), "GetFullUserName", arrSqlParam));
"Tampa .NET Koder" <Ta***********@discussions.microsoft.com> wrote in
message news:C3**********************************@microsof t.com...
ExecuteScalar returns a Object type..you should cast this object to a

string
like so:

strFullUserName = (string)
Utility.SqlHelper.ExecuteScalar(DB.getConnectiongS tring(),
"GetFullUserName", arrSqlParam);

"Neven Klofutar" wrote:
Hi,

I have a problem with SqlHelper.ExecuteScalar ...

When I try to execute SqlHelper.ExecuteScalar I get this message:
"System.InvalidCastException: Object must implement IConvertible.".

Help ...

Thanx, Neven

----------------------
SqlParameter[] arrSqlParam = null;
arrSqlParam =
SqlHelperParameterCache.GetSpParameterSet(DB.getCo nnectiongString(),
"GetFullUserName");
arrSqlParam[0].Value = strUserName;

strFullUserName = Utility.SqlHelper.ExecuteScalar(DB.getConnectiongS tring(), "GetFullUserName", arrSqlParam);

------------------------
CREATE PROCEDURE GetFullUserName
@strUserName nvarchar(50),
@strUserNameFull nvarchar(100) OUT
AS

SET @strUserNameFull = (SELECT ime + ' ' + prezime FROM tblUsers WHERE
[tblUsers].[user_name] = @strUserName)
GO


Nov 19 '05 #4

"Neven Klofutar" <neven.klofutar*r.e..mo*****@vip.hr> wrote in message
news:en**************@TK2MSFTNGP15.phx.gbl...
Hi,

I have a problem with SqlHelper.ExecuteScalar ...


Confusingly, ExecuteScalar is for commands which return result sets.
You want ExecuteNonQuery, and then examine the parameter.
David
Nov 19 '05 #5
you sp has no result set, so execute scaler is returning an error. execute
scalre returns the first column of the first result set. if there is no
result set, then its stuck.

change you proc to return the name in a result set, or use ExecuteNoQuery,
and get the value from the sp parameter (which must be declared an out in
your code to work).

-- bruce (sqlwork.com)
"Neven Klofutar" <neven.klofutar*r.e..mo*****@vip.hr> wrote in message
news:en**************@TK2MSFTNGP15.phx.gbl...
| Hi,
|
| I have a problem with SqlHelper.ExecuteScalar ...
|
| When I try to execute SqlHelper.ExecuteScalar I get this message:
| "System.InvalidCastException: Object must implement IConvertible.".
|
| Help ...
|
| Thanx, Neven
|
| ----------------------
| SqlParameter[] arrSqlParam = null;
| arrSqlParam =
| SqlHelperParameterCache.GetSpParameterSet(DB.getCo nnectiongString(),
| "GetFullUserName");
| arrSqlParam[0].Value = strUserName;
|
| strFullUserName =
Utility.SqlHelper.ExecuteScalar(DB.getConnectiongS tring(),
| "GetFullUserName", arrSqlParam);
|
| ------------------------
| CREATE PROCEDURE GetFullUserName
| @strUserName nvarchar(50),
| @strUserNameFull nvarchar(100) OUT
| AS
|
| SET @strUserNameFull = (SELECT ime + ' ' + prezime FROM tblUsers WHERE
| [tblUsers].[user_name] = @strUserName)
| GO
|
|
|
Nov 19 '05 #6
Uf ... Thanx I'll try this, I thought that Execute.Scalar returns a single
value, and that Execute.NoQuery is used when executing INSERT, DELETE or
UPDATE.

Neven
"bruce barker" <no***********@safeco.com> wrote in message
news:uS**************@TK2MSFTNGP11.phx.gbl...
you sp has no result set, so execute scaler is returning an error. execute
scalre returns the first column of the first result set. if there is no
result set, then its stuck.

change you proc to return the name in a result set, or use ExecuteNoQuery,
and get the value from the sp parameter (which must be declared an out in
your code to work).

-- bruce (sqlwork.com)
"Neven Klofutar" <neven.klofutar*r.e..mo*****@vip.hr> wrote in message
news:en**************@TK2MSFTNGP15.phx.gbl...
| Hi,
|
| I have a problem with SqlHelper.ExecuteScalar ...
|
| When I try to execute SqlHelper.ExecuteScalar I get this message:
| "System.InvalidCastException: Object must implement IConvertible.".
|
| Help ...
|
| Thanx, Neven
|
| ----------------------
| SqlParameter[] arrSqlParam = null;
| arrSqlParam =
| SqlHelperParameterCache.GetSpParameterSet(DB.getCo nnectiongString(),
| "GetFullUserName");
| arrSqlParam[0].Value = strUserName;
|
| strFullUserName =
Utility.SqlHelper.ExecuteScalar(DB.getConnectiongS tring(),
| "GetFullUserName", arrSqlParam);
|
| ------------------------
| CREATE PROCEDURE GetFullUserName
| @strUserName nvarchar(50),
| @strUserNameFull nvarchar(100) OUT
| AS
|
| SET @strUserNameFull = (SELECT ime + ' ' + prezime FROM tblUsers WHERE
| [tblUsers].[user_name] = @strUserName)
| GO
|
|
|

Nov 19 '05 #7
I just remembered and checked ... ExecuteNonQuery returns int ?

Neven
"bruce barker" <no***********@safeco.com> wrote in message
news:uS**************@TK2MSFTNGP11.phx.gbl...
you sp has no result set, so execute scaler is returning an error. execute
scalre returns the first column of the first result set. if there is no
result set, then its stuck.

change you proc to return the name in a result set, or use ExecuteNoQuery,
and get the value from the sp parameter (which must be declared an out in
your code to work).

-- bruce (sqlwork.com)
"Neven Klofutar" <neven.klofutar*r.e..mo*****@vip.hr> wrote in message
news:en**************@TK2MSFTNGP15.phx.gbl...
| Hi,
|
| I have a problem with SqlHelper.ExecuteScalar ...
|
| When I try to execute SqlHelper.ExecuteScalar I get this message:
| "System.InvalidCastException: Object must implement IConvertible.".
|
| Help ...
|
| Thanx, Neven
|
| ----------------------
| SqlParameter[] arrSqlParam = null;
| arrSqlParam =
| SqlHelperParameterCache.GetSpParameterSet(DB.getCo nnectiongString(),
| "GetFullUserName");
| arrSqlParam[0].Value = strUserName;
|
| strFullUserName =
Utility.SqlHelper.ExecuteScalar(DB.getConnectiongS tring(),
| "GetFullUserName", arrSqlParam);
|
| ------------------------
| CREATE PROCEDURE GetFullUserName
| @strUserName nvarchar(50),
| @strUserNameFull nvarchar(100) OUT
| AS
|
| SET @strUserNameFull = (SELECT ime + ' ' + prezime FROM tblUsers WHERE
| [tblUsers].[user_name] = @strUserName)
| GO
|
|
|

Nov 19 '05 #8

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

Similar topics

0
2964
by: Rajesh Madhra | last post by:
Hi everybody I just solved my probem about creating my own assemblies by using the command line vbc /nologo /t:library /out:MyClass.dll ... MyClass.vb with your help. But I still cannot make...
3
8383
by: Brian | last post by:
I am trying to pass a null value into a stored procedure so that it can save the data. I am using Microsoft's SQLHelper dll to do this. My example code is below. How do I pass in a null value...
0
1621
by: Rajesh Kumar | last post by:
Hi Gregory Thanks for your answer. I did not see any attached file so I copied your text into a text file and named it compiler.bat Checked the wrapped lines and runned the file. It said Dataset,...
0
3354
by: Rajesh Madhra | last post by:
Hi Gregory Thanks for your answer. I did not see any attached file so I copied your text into a text file and named it compiler.bat Checked the wrapped lines and runned the file. It said Dataset,...
1
3043
by: Chad Dittmer via .NET 247 | last post by:
I'm having problems inserting into Sql 2000 using SqlHelper.ExecuteScalar. When it inserts, it only takes the first character from the string?? Any help would be appreciated. Here is the code and...
4
2857
by: FyinsFlip | last post by:
Microsoft Data Access Blocks (SqlHelper) you can do an insert and get the new row ID without using a stored procedure? DataMembers.Car_IDObject = SqlHelper.ExecuteScalar( _connectionString ,...
7
7524
by: RJN | last post by:
Hi I want to get the rerurn value from a stored procedure My stored proc looks like this create proc test ..... if.. return 1
4
2112
by: John F | last post by:
Hello All, What is the consensus on using sqlhelper or not using sqlhelper when calling stored procedures? We're trying to go with a standard for our projects and personally I prefer not...
0
7126
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
7168
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,...
0
7210
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...
1
6891
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...
0
5465
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4595
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...
0
3087
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1424
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
293
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.