updating multiple columns in a row using ADO.net W/ VB.NET web form

net pwanage

New member
Joined
Dec 12, 2005
Messages
4
this is what i have so far for updaing one column but i need to update multiple columns in my form

Dim MyConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=yada_yada_yada.mdb")
MyConnection.Open
Dim MyCommand As New OleDbCommand("UPDATE Cust SET Fname = me.txtFname.text WHERE ID = txtUpdID", MyConnection)
MyCommand.ExecuteNonQuery()
MyConnection.Close
MyReader.Close
MyCommand.Dispose


anyway how would i go about doing an update for lets say
SET Fname = me.txtFname.text, Lname = me.txtLname.text, Mname = me.txtMname.text WHERE ID = me.txtUpdID;

i have been searching for some kind of code showing this but my searches come up NULL :(
 
OK i have made pretty good headway but now my execution button fails. what i have done is populated the textboxes by the row PK "ID" i now want to update that data that data that is presented

here is my commit change button code

Dim myCmd As New OleDb.OleDbCommand("UPDATE phonesOHM SET Name = " & Me.txtUpdName.Text & _
" ,Address = " & Me.txtUpdAddress.Text & _
" ,City = " & Me.txtUpdCity.Text & _
" ,State = " & Me.txtUpdState.Text & _
" ,Zip = " & Me.txtUpdZip.Text & _
" ,Phone = " & Me.txtUpdPhone.Text & "," & _
"WHERE ID = " & Me.txtUpdID.Text, myCnn)


myCmd.ExecuteNonQuery()
myCnn.Close()
myCmd.Dispose()

all of the data is properly collected i just dont think its sending it right back to access. any ideas? i think im having problems when i open and close the connections for the "populate button"?
 
nevermind I got it.

well I figured it out. If anybody was wondering the code for multiple column updates in a single row is.....

well first populate the textboxes with a simple select query
then.....

Private Sub btnUpdCommit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdCommit.Click

Dim myCnn As New OleDb.OleDbConnection

If myCnn.State = ConnectionState.Open Then
myCnn.Close()
End If
Dim mysql As String
myCnn.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=C:\Company\CompanyXP.mdb"
myCnn.Open()



Dim myCmd As New OleDb.OleDbCommand("UPDATE phonesOHM SET Name = " & Me.txtUpdName.Text & " ,Address = " & Me.txtUpdAddress.Text & " ,City = " & Me.txtUpdCity.Text & " ,State = " & Me.txtUpdState.Text & " ,Zip = " & Me.txtUpdZip.Text & " ,Phone = " & Me.txtUpdPhone.Text & " WHERE ID = " & CInt(Me.txtUpdID.Text), myCnn)

Try
myCmd.ExecuteNonQuery()
myCnn.Close()
myCmd.Dispose()
Catch ex As Exception
MsgBox("error! error! w00t! w00t!: " & vbCrLf & ex.Message)
End Try
End Sub

-JB
 
Back
Top