using parameters

vogaga

New member
Joined
May 15, 2006
Messages
1
Programming Experience
Beginner
Hello I am just trying to use parameters in my Insert and Update statements but not having any luck can anyone help me. I do not get any errors but nothing is inserted or updated


Public
Sub CreateConnection()
Dim cnStr AsString = "dsn=MYSQLDSN;server=putslind02;user id=request; password=r3qu3st; database=addr_request; pooling=false"
mysqlCn.ConnectionString = cnStr
Dim TransCommand AsNew OdbcCommand
TransCommand.Connection = mysqlCn
Dim TransCommandStr AsString
TransCommandStr = "Select owner_name From address_forms Order by owner_name"
TransCommand.CommandText = TransCommandStr
da.SelectCommand = TransCommand

cmdInsert.Connection = mysqlCn
cmdInsert.CommandText = "Insert Into address_forms (owner_name) Values (NewName)"
With cmdInsert.Parameters
.Add("?NewName", DbType.String)
EndWith
da.InsertCommand = cmdInsert

cmdUpdate.Connection = mysqlCn
cmdUpdate.CommandText = "Update address_forms Set owner_name = @NewName Where owner_name = @OldName"
With cmdUpdate.Parameters
.Add("NewName", DbType.String, 50, "owner_name")
.Add("@OldName", DbType.String, 50, "owner_name")
EndWith
Try
mysqlCn.Open()
da.Fill(ds, "address_forms")
Catch Odbc As OdbcException
MsgBox(Odbc.Message, "Odbc Server Error")
EndTry
mysqlCn.Close()
EndSub

PrivateSub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
If bNewRow Then
Me.SetNewValues(cmdInsert)
Try
mysqlCn.Open()
MsgBox(cmdInsert.Parameters("?NewName").Value)
MsgBox(cmdInsert.CommandText)
cmdInsert.ExecuteNonQuery()
mysqlCn.Close()
bNewRow =
False
Catch odbc As OdbcException
MsgBox(odbc.Message, MsgBoxStyle.Information)
EndTry
EndIf
'MsgBox("You have inserted a record for " & strowner)
EndSub

PrivateSub SetNewValues(ByVal cmd As OdbcCommand)
With cmd
.Parameters("?NewName").Value = TextBox1.Text
EndWith
EndSub
 
Top Bottom