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))
 

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"))
 

DonManfred

Expert
Licensed User
Last edited:
Top