Android Question Insert MSSQL

DataProtec

Member
Licensed User
Got a problem to insert new data in MSSQL DB
IN VB NET i do
aCmd.Parameters.AddWithValue("@UserID", IIf(aktUser_ID = "", DBNull.Value, aktUser_ID))

In V4A i tried what i found in the Fórum, but get the Msg " java.sql.SQLException: Invalid parameter index 1."
Public msSQL As JdbcSQL
msSQL.ExecNonQuery2("INSERT INTO CheckInOut_Table VALUES('UserID')", Array As Object("56"))
What i doing wrong
thanks
Uli
 

rraswisak

Active Member
Licensed User
you should use this way:

B4X:
msSql.ExecNonQuery2("Insert Into CheckInOut Values (?)", Array As Object("56"))

i assume that CheckInOut table has only one field. If you have several field then you should explicitly call the field name, example:
B4X:
msSql.ExecNonQuery2("Insert Into Table1 (Field1, Field2) Values (?, ?)", Array As Object(value1, value2))
 
Upvote 0

DataProtec

Member
Licensed User
Hello, thanks for reply
I did exactly what you recommend, the DB has more fielda but i need to put this field and
if i execute th app it crash with the following Error
B4X:
Error occurred on line: 220 (Main)  '*** the with the insert
java.sql.SQLException: Invalid parameter index 1.
220  msSQL.ExecNonQuery2("insert into CheckInOut_Table (UserID) Values(56)", Array As Object("56"))
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
What is V4A? There is no such thing in B4X

Public msSQL As JdbcSQL
msSQL.ExecNonQuery2("INSERT INTO CheckInOut_Table VALUES('UserID')", Array As Object("56"))
Please use [CODE]code here...[/CODE] tags when posting code.
codetag001.png

codetag002.png

codetag003.png
 
Last edited:
Upvote 0
Top