|
-
Jan 16th, 2004, 03:51 PM
#1
Thread Starter
Fanatic Member
Update field in data row
Hi guys. I know how to create a new record in a database. What I don't know is how to update one field in a database record.
This is the code I would use to create a new record.
VB Code:
Dim datAdapt As New OleDb.OleDbDataAdapter("Select * From CigUnits", cn2)
Dim commBuild As New OleDb.OleDbCommandBuilder(datAdapt)
Dim datSet As New Data.DataSet()
Dim datRow As Data.DataRow
datSet.Clear()
datAdapt.Fill(datSet, "CigUnits")
datRow = datSet.Tables("CigUnits").NewRow
datRow.Item("EmpID") = Request.Cookies("EmpID").Value
datRow.Item("Store") = datRead.Item("location")
datRow.Item("BusiDate") = datRead.Item("Date")
datRow.Item("PC") = datRead.Item("ProductCode")
datSet.Tables("CigUnits").Rows.Add(datRow)
datAdapt.Update(datSet, "CigUnits")
Can someone please give me an example of some code where I can find a particular record, and then update one field in that record.
Thanks!
-
Jan 16th, 2004, 04:00 PM
#2
Frenzied Member
VB Code:
Dim Conn As New OleDbConnection("Your Connectionstring")
Dim Cmd As New OleDbCommand("UPDATE TableName SET fieldName = whatever", Conn)
Try
Conn.Open()
Cmd.ExecuteNonQuery()
Conn.Close()
Catch ex As Exception
'catch the exception
End Try
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Jan 16th, 2004, 04:10 PM
#3
Addicted Member
The code that " Memnoch1207" used is exactly what i use, but just remember the 'WHERE' part of the update statement:
Dim Cmd As New OleDbCommand("UPDATE TableName SET fieldName = whatever WHERE PrimaryKey/FieldName='" & IDofitem/CurrentNameofItem you want to update & "'", Conn)
If you don't specify the exact record, the update statement will act on all of the records in the DB.
If the facts don't fit the theory, change the facts. --Albert Einstein
-
Jan 16th, 2004, 04:16 PM
#4
Thread Starter
Fanatic Member
Memnoch1207, could you please show me an example of some code where you go through a do while loop, read one field from a record, then update another field?
Thanks for your help.
If you don't specify the exact record, the update statement will act on all of the records in the DB.
Like, Duh! lol
-
Jan 16th, 2004, 04:18 PM
#5
Thread Starter
Fanatic Member
Memnoch1207, nevermind. I can use a data reader, get the one value, then use your code to update the other field...
Thanks again.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|