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?

Thanks!

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=10.0.1.11;UserID=edith;password=edith;"
conn = New iDB2Connection(str)
conn.Open()

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

conn.Close()

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=10.0.1.11;UserID=edith;password=edith;"
conn = New iDB2Connection(str)
conn.Open()

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
cmdDelete.ExecuteNonQuery()

conn.Close()

MsgBox("Delete Successful!")

Response.Redirect("Test.aspx")
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.