TableAdapter Update Query Not Working

Hello Exports,

I'm working with a tableadapter.  Manually created the update query.  It's not updating and no error is coming out.  The data is in SQL server. The empID is defined as the primary key in the sql table.  After I click the update button I double checked in SSMS to see if the record changed - but it didn't.

Here's the front page code:
<form id="form1" runat="server">
<table class="style1" border="1">
<tr>
<td class="style2"></td>
<td class="style3" colspan="2">
   <asp:Label ID="lbl1" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<td class="style2">#</td>
<td class="style3"><asp:TextBox ID="empnumtb" runat="server"></asp:TextBox>
</td>
<td>
   <asp:HiddenField ID="hdnID" runat="server" value="1"/>
</td>
</tr>
<tr>
<td class="style4"></td>
<td colspan="2" class="style5">
   FName <asp:TextBox ID="fnametb" runat="server"></asp:TextBox>
   LName <asp:TextBox ID="lnametb" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">Area</td>
<td colspan="2"><asp:TextBox ID="areatb" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2"></td>
<td colspan="2">
<asp:Button ID="btnAdd" runat="server" Text="Add1" />  
<asp:Button ID="btnAddDS" runat="server" Text="AddDS" />
<asp:Button ID="btnUpdate" runat="server" Text="Update1" Width="61px" />
<asp:Button ID="btnUpdateDS" runat="server" Text="UpdateDS" />
<asp:Button ID="btnDelete" runat="server" Text="Delete" />
</td>
</tr>
<tr>
<td class="style2"><asp:TextBox ID="empID" runat="server"></asp:TextBox>
</td>
<td colspan="2"><asp:Button ID="SearchBtn" runat="server" Text="Search for 1" />
</td>
</tr>
<tr>
<td class="style2"> All Empls</td>
<td colspan="2">Select Emp
<asp:Label ID="lbl2" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<td class="style2">  This grid fills in on page load
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="EmpID" HeaderText="ID" ReadOnly="True" />
<asp:BoundField DataField="EmployeeNumber" HeaderText="Emp #" />
<asp:BoundField DataField="FName" HeaderText="First Name" />
<asp:BoundField DataField="LName" HeaderText="Last Name" />
<asp:BoundField DataField="Area" HeaderText="Area" />
<asp:CommandField ButtonType="Button" ShowSelectButton="True" />
</Columns>
</asp:GridView>
</td>
<td colspan="2" valign="top">
<asp:GridView ID="GridView2" runat="server" AllowSorting="True" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="EmpID" HeaderText="ID" ReadOnly="True" />
<asp:BoundField DataField="EmployeeNumber" HeaderText="Emp #" />
<asp:BoundField DataField="FName" HeaderText="First Name" />
<asp:BoundField DataField="LName" HeaderText="Last Name" />
<asp:BoundField DataField="Area" HeaderText="Area" />
<asp:CommandField ButtonType="Button" ShowSelectButton="True" />
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</form>

Here's the code-behind:
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Imports EmployeeTableAdapters

Partial Class DUTest
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim allEmps As New EmployeeTableAdapters.employeesTableAdapter
        GridView1.DataSource = allEmps.GetAllEmployeeData()
        GridView1.DataBind()

    End Sub

    Protected Sub SearchBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SearchBtn.Click

        Dim employeesAdapter As New employeesTableAdapter
        Dim IDStr As String = empID.Text
        Response.Write("top " & empID.Text)
        GridView2.DataSource = employeesAdapter.GetEmployeeByEmpID(empID.Text)
        GridView2.DataBind()

    End Sub

    Protected Sub btnAdd_Click(sender As Object, e As System.EventArgs) Handles btnAdd.Click
        'This uses the GUI Dataset - Rt Clk Add New Item - Dataset
        Dim employeeNumber, FName, LName, Area As String
        Dim recUpdate As Integer
        Dim taEmployee As New EmployeeTableAdapters.employeesTableAdapter

        employeeNumber = empnumtb.Text
        FName = fnametb.Text
        LName = lnametb.Text
        Area = areatb.Text

        recUpdate = taEmployee.InsertEmployeeQuery(employeeNumber, FName, LName, Area)
        lbl1.Text = recUpdate

    End Sub

    Protected Sub GridView1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles GridView1.SelectedIndexChanged
        Dim row As GridViewRow = GridView1.SelectedRow
        empnumtb.Text = row.Cells(1).Text
        fnametb.Text = row.Cells(2).Text
        lnametb.Text = row.Cells(3).Text
        areatb.Text = row.Cells(4).Text
        hdnID.Value = row.Cells(0).Text
        lbl1.Text = row.Cells(0).Text
    End Sub

    Protected Sub btnUpdate_Click(sender As Object, e As System.EventArgs) Handles btnUpdate.Click
        Dim EmpNum, FName, LName, Area As String
        Dim ID, recUpdate As Integer
        Dim taEmployee As New EmployeeTableAdapters.employeesTableAdapter

        ID = hdnID.Value
        EmpNum = empnumtb.Text
        FName = fnametb.Text
        LName = lnametb.Text
        Area = areatb.Text

        lbl2.Text = "ID = " & ID & ", Emp# = " & EmpNum & ", Name = " & FName & " " & LName & ", Area = " & Area & " ** / hdnID " & hdnID.Value.ToString
        Try
            recUpdate = taEmployee.UpdateEmployeeQuery(ID, EmpNum, FName, LName, Area)
        Catch ex As Exception
            lbl2.Text = ex.ToString
        End Try
    End Sub

 Screenshot of GUI XSD fileCode on UpdateEmployeeQuery:
UPDATE  employees
SET         EmployeeNumber =@EmployeeNumber,  Fname =@FName, Lname =@LName,  Area =@Area
WHERE   Empid =@EmpID

Any Ideas?
LVL 2
jshesekAsked:
Who is Participating?
 
jshesekConnect With a Mentor Author Commented:
Didn't solve what's causing this to not work.  But I did go another route.  Created a stored procedure in SSMS and called that.  Works like a charm.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.