Solved

error converting data typa nvarchar to int

Posted on 2013-02-05
3
481 Views
Last Modified: 2013-02-05
I have code behiind a form which triggers a sp in sql server. It should return a GroupID (integer) but I am getting the above error.

Any ideas where my code is wrong?

Dim myConn As ADODB.Connection
Dim objCom As ADODB.Command
Dim rsTemp As ADODB.Recordset

'Initialize variables
Set myConn = New ADODB.Connection
Set objCom = New ADODB.Command
    
'Open the connection, using your connection string
myConn.Open GetConnectString

With objCom
     .CommandText = "sp_Access_AddTranslationContract"     'Name of the stored procedure
     .CommandType = adCmdStoredProc  'Type : stored procedure
     .ActiveConnection = GetConnectString
    .Parameters.Append .CreateParameter("@societeID", adInteger, adParamInput, , Forms![frmtrad_commandes2]![societeID])
    .Parameters.Append .CreateParameter("@GroupName", adVarWChar, adParamInput, 150, Me.tmpGroupName)
    .Parameters.Append .CreateParameter("@ClientCode", adVarWChar, adParamInput, 50, Forms![frmtrad_commandes2]![ClientCode])
    .Parameters.Append .CreateParameter("@ClientReference", adVarWChar, adParamInput, 150, Me.ClientReference)
End With
 
'Store the result in a recordset
Set rsTemp = objCom.Execute
   
Dim intGroupID As String

With rsTemp
intGroupID = rsTemp("GroupID")
.Close
End With

Open in new window


sp
ALTER PROCEDURE [dbo].[sp_Access_AddTranslationContract]
	-- Add the parameters for the stored procedure here
@GroupName nvarchar(150),
@ClientCode nvarchar (50),
@societeID int,
@ClientReference nvarchar(150)
As
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

Declare @tmpRP as table(GroupID int)
Insert tblTranslationContractGroup
(DateStart, GroupName, Active, ClientCode, PrivilegeContract, societeID, ClientReference)
Output inserted.GroupID into @tmpRP
VALUES(GETDATE(), @GroupName, 1, @ClientCode, 1, @societeID, @ClientReference) 

SET NOCOUNT OFF -- for final select

Select * from @tmpRP

END

Open in new window

0
Comment
Question by:Shawn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Author Comment

by:Shawn
ID: 38857798
I have narrowed it down to this line
    .Parameters.Append .CreateParameter("@societeID", adInteger, adParamInput, 4, Forms![frmtrad_commandes2]![societeID])

still not sure what the fix is though. In sql server this is an initeger field
0
 
LVL 39

Accepted Solution

by:
appari earned 500 total points
ID: 38857799
Code looks fine. Did you try executing the procedure directly from sqlserver management studio? not sure if the order of parameters is causing the error.
try changing

With objCom
     .CommandText = "sp_Access_AddTranslationContract"     'Name of the stored procedure
     .CommandType = adCmdStoredProc  'Type : stored procedure
     .ActiveConnection = GetConnectString
    .Parameters.Append .CreateParameter("@societeID", adInteger, adParamInput, , Forms![frmtrad_commandes2]![societeID])
    .Parameters.Append .CreateParameter("@GroupName", adVarWChar, adParamInput, 150, Me.tmpGroupName)
    .Parameters.Append .CreateParameter("@ClientCode", adVarWChar, adParamInput, 50, Forms![frmtrad_commandes2]![ClientCode])
    .Parameters.Append .CreateParameter("@ClientReference", adVarWChar, adParamInput, 150, Me.ClientReference)
End With

to


With objCom
     .CommandText = "sp_Access_AddTranslationContract"     'Name of the stored procedure
     .CommandType = adCmdStoredProc  'Type : stored procedure
     .ActiveConnection = GetConnectString
    .Parameters.Append .CreateParameter("@GroupName", adVarWChar, adParamInput, 150, Me.tmpGroupName)
    .Parameters.Append .CreateParameter("@ClientCode", adVarWChar, adParamInput, 50, Forms![frmtrad_commandes2]![ClientCode])
    .Parameters.Append .CreateParameter("@societeID", adInteger, adParamInput, , Forms![frmtrad_commandes2]![societeID])
    .Parameters.Append .CreateParameter("@ClientReference", adVarWChar, adParamInput, 150, Me.ClientReference)
End With

0
 
LVL 1

Author Comment

by:Shawn
ID: 38857817
wow, that simple. It was the order. thank you
0

Featured Post

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question