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:

  1. execute stored procedure explicit parameters (see here example). not ever dump parameters query string.
  2. always list columns insert. so, should insert orders(col1, col2, col3, . . .) whatever columns including.
  3. use identity ordernr calculated automatically database. can value using output clause in insert.
  4. similarly, might want besteldatum default current date -- or not. i'm not sure column is, default appropriate create date column.
  5. surround entire body of stored procedure in own begin/end block (don't depend on begin transaction.

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -