?
Solved

TableAdapter Update Query Not Working

Posted on 2011-10-13
1
Medium Priority
?
644 Views
Last Modified: 2012-05-12
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?
0
Comment
Question by:jshesek
1 Comment
 
LVL 2

Accepted Solution

by:
jshesek earned 0 total points
ID: 36963883
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

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question