|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Help. Error converting nvarchar to numeric?It's purpose is to query the sql server, and return me a count. Here is the function: Private Function _countCallsCameIn(ByVal ApplicNum As String, ByVal date1 As String, ByVal date2 As String) As Integer '...the query were going to use... Dim lookupQuery As String = "SELECT COUNT(APPLIC_NUM) AS theCount FROM ACD_CALLDETAIL WHERE (APPLIC_NUM = @ApplicNum) AND (ORIG_DATE >= @beginDate) AND (ORIG_DATE < @endDate) AND (TALK_TIME > 0)" Dim theCommand As SqlCommand = New SqlCommand(lookupQuery, sqlConn) 'the command. theCommand.Parameters.Add("@ApplicNum", ApplicNum) 'the applicNum value theCommand.Parameters.Add("@beginDate", date1) 'begin date value theCommand.Parameters.Add("@endDate", date2) 'end date value Dim temp As Integer 'create the temp value for the count sqlConn.Open() 'open the connection temp = theCommand.ExecuteScalar 'throw the return value into the temp sqlConn.Close() 'close the connection Return temp 'return the count! End Function When I try to get that value by using this statement: value = a.countCallsCameIn(applicNum, beginDate, endDate) It throws this error: System.Data.SqlClient.SqlException: Error converting data type nvarchar to numeric. at System.Data.SqlClient.SqlDataReader.Read() at System.Data.SqlClient.SqlCommand.ExecuteScalar() at hnflash.COX.data.Aspect._countCallsCameIn(String ApplicNum, String date1, String date2) in C:\Documents and Settings\ckriutzf\VSWebCache\clas0dv02\hnflash\gatherData.vb:line 19... Any ideas? When I go into query analyzer, and use this query, with actuall values, it executes just fine. Thanks for the help! Casey (Ca***@discussions.microsoft.com) writes:
Show quote > Okay. I have this function in vb.net. I think you should you specify a parameter type for the parameter.> It's purpose is to query the sql server, and return me a count. > Here is the function: > > Private Function _countCallsCameIn(ByVal ApplicNum As String, ByVal date1 > As > String, ByVal date2 As String) As Integer > '...the query were going to use... > Dim lookupQuery As String = "SELECT COUNT(APPLIC_NUM) AS > theCount FROM ACD_CALLDETAIL WHERE (APPLIC_NUM = @ApplicNum) AND > (ORIG_DATE >= @beginDate) AND (ORIG_DATE < @endDate) AND (TALK_TIME > 0)" > Dim theCommand As SqlCommand = New SqlCommand(lookupQuery, sqlConn) > 'the command. > theCommand.Parameters.Add("@ApplicNum", ApplicNum) 'the applicNum value Now you get a nvarchar parameter, and then there is some conversion on the SQL Server side. If the number can have a decimal delimiter, this will fail, if the regional settings specify comma as the delimiter, as SQL Server only understands decimal points for conversion to numeric. -- Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp So how and where would I do that? In my SQL query?
Show quote "Erland Sommarskog" wrote: > Casey (Ca***@discussions.microsoft.com) writes: > > Okay. I have this function in vb.net. > > It's purpose is to query the sql server, and return me a count. > > Here is the function: > > > > Private Function _countCallsCameIn(ByVal ApplicNum As String, ByVal date1 > > As > > String, ByVal date2 As String) As Integer > > '...the query were going to use... > > Dim lookupQuery As String = "SELECT COUNT(APPLIC_NUM) AS > > theCount FROM ACD_CALLDETAIL WHERE (APPLIC_NUM = @ApplicNum) AND > > (ORIG_DATE >= @beginDate) AND (ORIG_DATE < @endDate) AND (TALK_TIME > 0)" > > Dim theCommand As SqlCommand = New SqlCommand(lookupQuery, sqlConn) > > 'the command. > > theCommand.Parameters.Add("@ApplicNum", ApplicNum) 'the applicNum value > > I think you should you specify a parameter type for the parameter. > Now you get a nvarchar parameter, and then there is some conversion > on the SQL Server side. If the number can have a decimal delimiter, > this will fail, if the regional settings specify comma as the delimiter, > as SQL Server only understands decimal points for conversion to numeric. > > > -- > Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se > > Books Online for SQL Server SP3 at > http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp > > Casey (Ca***@discussions.microsoft.com) writes:
> So how and where would I do that? In my SQL query? No, in Parameters.Add. There are a couple of overloads to this function,and there is one with type as well. Please refer to MSDN Library for details. -- Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp |
|||||||||||||||||||||||