Good Afternoon Everyone! :)
I am working on the update command for my DataGrid and i am following a examples from two sources one is the Beginning Dynamic Websites book by Wrox and one is a tutorial from 4guysfromrolla.
Something is not write in code as it is causing an error could you please give me some advice.. they both different methods it appears. This is my code:
Sub dgSubCategories_UpdateCommand(sender As Object, e As DataGridCommandEventArgs)
Dim connectionString As String = ConfigurationSettings.AppSettings("ConnectionStrin g")
Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString )
Dim SubCategoryName as String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
Dim CategoryName as String = CType(e.Item.Cells(3).Controls(0), TextBox).Text
Dim CategoryID as Integer = CType(e.Item.Cells(4).Controls(0), TextBox).Text
Dim queryString As String = "UPDATE [tblSubCategory] SET [CategoryID]=@CategoryID, [SubCategoryName]=@SubCateg"& _
"oryName, [CategoryName]=@CategoryName"
Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dbParam_subCategoryName As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
dbParam_subCategoryName.ParameterName = "@SubCategoryName"
dbParam_subCategoryName.Value = subCategoryName
dbParam_subCategoryName.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_subCategoryName)
Dim dbParam_categoryID As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
dbParam_categoryID.ParameterName = "@CategoryID"
dbParam_categoryID.Value = categoryID
dbParam_categoryID.DbType = System.Data.DbType.Int32
dbCommand.Parameters.Add(dbParam_categoryID)
Dim dbParam_categoryName As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
dbParam_categoryName.ParameterName = "@CategoryName"
dbParam_categoryName.Value = categoryName
dbParam_categoryName.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_categoryName)
dbCommand.ExecuteNonQuery
dbConnection.Close
dgSubCategories.EditItemIndex = -1
End Sub
Can anyone tell me if there is a simpler way of doing this... and can i use ddl in there so when they select a category it not only updates the categoryName but the categoryID at the same time?
Are there any real good tutorials out there for this that anyone knows of? Thanks for any help you can give. :D
David Jenkins
-------------------------------------------------------------
Do you want to make extra money around your commitments?
Credit cards, bills, loans and a mortgage - all getting you down?
Is your pension going to be enough when you retire?
There is a solution visit
http://www.1stmillion.co.uk
or call 01772 489521