sql - Cannot find the Nvarchar to Int conversion in my code -
i making project school have make program can create orders in. when try create orders error returned me.
error converting data type nvarchar int.
in advance i'm sorry if basic question easely spotted. me , project members beginning programmers cannot spot goes wrong.
the code execute in vba :
set rs = dbconn.execute("exec sporderplaatsen '" & me.tbtijd & "', " & me.klantnr & ", '" & me.tbophaaldatum & "', '" & me.tbafleverdatum & "', '" & me.tbophaaladres & "', " & me.tbpalletnr & ", " & me.tbaantalpallets & "")
this code execute's our stored procedure. stored procedure looks this.
create procedure sporderplaatsen ( @tijd time(0), @klantnr integer, @ophaaldatum date, @afleverdatum date, @palletnr integer, @aantal integer, @adres varchar(255) ) begin transaction declare @ordernr int declare @besteldatum date set @besteldatum = getdate() select @ordernr = max(o.ordernr) + 1 orders o insert orders values (@ordernr, @besteldatum, @tijd, @klantnr, @ophaaldatum, @afleverdatum, @adres) insert orderregel values (@ordernr, @palletnr, @aantal) if @@error <> 0 begin rollback raiserror ('error tijdens het plaatsen van order.', 16, 1) return end commit go
somehow conversion error cannot find.
could any1 figure out us? appreciated
there multiple places going wrong. here advice:
- execute stored procedure explicit parameters (see here example). not ever dump parameters query string.
- always list columns
insert
. so, shouldinsert orders(col1, col2, col3, . . .)
whatever columns including. - use
identity
ordernr
calculated automatically database. can value usingoutput
clause ininsert
. - similarly, might want
besteldatum
default current date -- or not. i'm not sure column is, default appropriate create date column. - surround entire body of stored procedure in own
begin
/end
block (don't depend onbegin transaction
.
Comments
Post a Comment