Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

error converting data typa nvarchar to int

Posted on 2013-02-05
3
Medium Priority
?
507 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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

597 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