Start New Discussion within our Software Development Community

Hi! I already established an iDB2Connection, now what I want to know, is how could I execute SQL Queries for INSERT, DELETE and UPDATE. I had tested the code already and it works. The code for count works; I get the total number of records.

My question is that for the UPDATE one, this does not work :( any problem or missing line of code?


Imports IBM.Data.DB2
Imports IBM.Data.DB2.iSeries

Dim str, sql, sqlUpdate As String
Dim conn As New iDB2Connection
Dim cmd, cmdUpdate As New iDB2Command
Dim count As Integer

'Opening of iDB2Connection
str = "Datasource=;UserID=edith;password=edith;"
conn = New iDB2Connection(str)

'SQL Query
sql = "SELECT COUNT(*) AS count FROM ictms.import"
cmd = New iDB2Command(sql, conn)

'SQL Query Execution
count = Convert.ToInt32(cmd.ExecuteScalar)

sqlUpdate = "UPDATE ictms.import SET document_number=123456 WHERE recid=11186"
cmdUpdate = New iDB2Command(sqlUpdate, conn)


Just want to share with you guys my line of code :)

'*****************************Opening of iDB2Connection
Dim str, sqlDelete As String
Dim conn As New iDB2Connection
Dim cmdDelete As New iDB2Command

str = "Datasource=;UserID=edith;password=edith;"
conn = New iDB2Connection(str)

sqlDelete = "DELETE FROM ictms.import WHERE recid=@recid"

cmdDelete.Parameters.Add("recid", iDB2DbType.iDB2Integer)
cmdDelete.Parameters("recid").Value = Label1.Text

cmdDelete.Connection = conn
cmdDelete.CommandText = sqlDelete


MsgBox("Delete Successful!")

This question has already been answered. Start a new discussion instead.