I am having problems with the following code. I am trying to update my db table Categories in Northwind. I have borrowed this code from www.dotnetjohn.com/articles/articleid27.aspx Although it works on dotnetjohn website, I cannot replicate the code successfully. I have a datagrid filled with data and two textboxes with an “Insert” button. When the button is pressed, the text entered into the two textboxes is to be added to the table Categories in Northwind db. I cannot get the click event to update the database and add a new record entry. The page_load fills the datagrid with data from a SELECT statement. The Insert_Click should take the entries from two textboxes and insert them into the Northwinds database Categories table. I have enclosed the basic components of my .aspx.vb page for the Page_Load, Insert_Click, and FilltheGrid() method. I am confused as to my problem. Please help. Thank you. If you need more data just ask me to provide it
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Loa
If Not Page.IsPostBack The
Dim dsCategories As DataSe
Dim temp As Object = Session("Catego ries"
If temp Is Nothing The
dsCategories = New DataSe
Dim sqlConn As String = "server=BP-ADOVE;database= northwind;uid=s a;pwd=
Dim selectText As Strin
selectText = "SELECT categoryName, Description FROM Categories WHERE (CategoryID = 1 or CategoryID=2 or CategoryID=3 or CategoryID=9)
Dim cmdCategories As SqlDataAdapter = New SqlDataAdapter( selectText, sqlConn
cmdCategories.F ill(dsCategorie s, "Categories "
Session("Catego ries") = dsCategorie
Els
dsCategories = CType(temp, DataSet
End I
dgAction.DataSo urce = dsCategories.Ta bles("Categorie s"
dgAction.DataBi nd(
End I
End Su
Sub btnInsert_Click (ByVal Sender As Object, ByVal e As EventArgs) Handles btnInsertAction .Clic
If Page.IsValid The
Dim strDate As Strin
Dim strDesc As Strin
objConn = New SqlConnection(C onfigurationSet tings.AppSettin gs("connectionS tring")
objConn.Open(
strDate = txtActionDate.T ext.Trim(
strDesc = txtDescription. Text.Trim(
strSql = "INSERT INTO Employees (LastName, FirstName) "
& "VALUES ('" & strDate & "', '" & strDesc & "')
objCmd = New SqlCommand(strS ql, objConn
objCmd.ExecuteN onQuery(
'Dim cmdCategories As SqlDataAdapter = New SqlDataAdapter( strSql, objConn
'cmdCategories. Fill(dsCategori es, "Categories "
'dgAction.DataS ource = dsCategories.Ta bles(0).Default Vie
'dgAction.DataB ind(
objCmd.ExecuteN onQuery(
objConn.Close(
FillTheGrid(
End I
End Su
Sub FillTheGrid(
'Dim adoComponent As ADOCOM.DataClas s = New ADOCOM.DataClas
'Dim adoRS As ADODB._Recordse t = adoComponent.Ge tData(
Dim myDA As SqlDataAdapter = New SqlDataAdapte
Dim ds As DataSet = New DataSe
myDA.InsertComm and = objCm
Dim dt As DataTable = ds.Tables("Empl oyees"
myDA.TableMappi ngs.Add("Employ ees", "Employees"
myDA.Update(ds, "Employees"
'dataAdapter.Fi ll(ds
dgAction.DataSo urce = ds.Tables("Empl oyees") '.DefaultVie
dgAction.DataBi nd(
End Sub