Here is the code i have for sql server:
Sub DBUpdateDataGrid_Update(source As Object, E As DataGridCommandEventArgs)
Dim objCommand As SqlCommand
Dim strSQLQuery As String
' Our update command. I'm using parameters this time around.
' We'll set the parameter values a few lines down.
strSQLQuery = "UPDATE scratch " _
& "SET text_field = @TextValue, " _
& "integer_field = @IntValue, " _
& "date_time_field = @DTValue " _
& "WHERE id = @ID"
' Create new command object passing it our SQL update
' command and telling it which connection to use.
objCommand = New SqlCommand(strSQLQuery, objConnection)
' Add parameters that our SQL update command needs:
objCommand.Parameters.Add(New SqlParameter("@ID", SqlDbType.Int))
objCommand.Parameters.Add(New SqlParameter("@TextValue", SqlDbType.VarChar, 255))
objCommand.Parameters.Add(New SqlParameter("@IntValue", SqlDbType.Int))
objCommand.Parameters.Add(New SqlParameter("@DTValue", SqlDbType.DateTime))
' Set the values of these parameters:
' This comes from our datagrid telling us which item to update.
objCommand.Parameters("@ID").Value = DBUpdateDataGrid.DataKeys(E.Item.ItemIndex)
' These can obviously come from anywhere... I'm just pulling
' in strings and numbers from the current time & date so
' I can keep the sample simple and not involve an input form.
' In a real world example you'd probably pull them from data
' that a user entered.
objCommand.Parameters("@TextValue").Value = CStr(WeekdayName(WeekDay(Now())))
objCommand.Parameters("@IntValue").Value = CInt(Day(Now()))
objCommand.Parameters("@DTValue").Value = Now()
' Open the connection, execute the command, and close the connection.
objConnection.Open()
objCommand.ExecuteNonQuery()
objConnection.Close()
' Record is now updated... you should add appropriate error handling.
' Refresh our Datagrid to show the record is updated with new data.
ShowDataGrid()
End Sub
I am confused on how to convert this for an Access DB.
|