strange update problem .net | Newbie | | Join Date: Nov 2008
Posts: 1
| |
Hi guys -
I have written a form, and a stored procedure to update the said form.
It really is as simple as that. A user can go into the form, update some fields and hit the update button to update the information which is stored in a SQL database.
In testing we noticed that the form was updating correctly but the update mechanism was also updating the first record of the table in the sql database every time. No error messages are on screen - it looks like everything has happened correctly until you go into the table manually and realise it has updated the first record of the table with exacly the same info as the correct record.
We have tried a number of things here to stop it updating the first record, but can't manage it. It's like the update completely ignores the unique identifier and decides it's going to update the first record in the table also.
Has anyone had trouble like this before?
This is a fairly important application, so if anyone could shed some light on it that would be great.
I have included as much code as I can below - there is an awful lot of it.
If there are any questions you have you need clarified I'd be happy to do that.
Many thanks in advance.
DS
Code Behind -
Partial Class css_ESA55pbc
-
Inherits System.Web.UI.Page
-
' Procedure to insert the form
-
Protected Sub InsertButton_Click1(ByVal sender As Object, ByVal e As System.EventArgs)
-
Try
-
'Create a New Connection for the Stored Procedure
-
Dim myConnection As New Data.SqlClient.SqlConnection(Me.SqlDataSource1.ConnectionString)
-
myConnection.Open()
-
Dim myCommand As New Data.SqlClient.SqlCommand("INSERT_FORM", myConnection)
-
myCommand.CommandType = Data.CommandType.StoredProcedure
-
-
'Add the INSERT parameters
-
myCommand.Parameters.AddWithValue("Case_Id", CType(Me.FormView1.FindControl("Case_IDLabel"), Label).Text)
-
-
myCommand.Parameters.AddWithValue("Form_Id", CType(Me.FormView1.FindControl("Form_IDLabel"), Label).Text)
-
-
myCommand.Parameters.AddWithValue("Date_Issued", Convert.ToDateTime(CType(Me.FormView1.FindControl("Date_Issued"), TextBox).Text))
-
-
myCommand.Parameters.AddWithValue("BF_Date", Convert.ToDateTime(CType(Me.FormView1.FindControl("BF_DateTextBox"), TextBox).Text))
-
-
' Test to see if Returned Date Text Box is a null value
-
' if yes insert null
-
If ((CType(Me.FormView1.FindControl("Returned_DateTextBox"), TextBox).Text <> "")) Then
-
myCommand.Parameters.AddWithValue("Returned_Date", Convert.ToDateTime(CType(Me.FormView1.FindControl("Returned_DateTextBox"), TextBox).Text))
-
-
Else : myCommand.Parameters.AddWithValue("Returned_Date", DBNull.Value)
-
-
End If
-
-
myCommand.Parameters.AddWithValue("Na", CType(Me.FormView1.FindControl("NA"), CheckBox).Checked)
-
-
myCommand.Parameters.AddWithValue("Notes", CType(Me.FormView1.FindControl("NotesTextBox"), TextBox).Text)
-
-
'Execute the command
-
myCommand.ExecuteReader()
-
'Response.Redirect("~/GenericErrorPage.aspx", False)
-
-
myConnection.Close()
-
'Declare variables and assign values
-
Dim CaseRef As String = CType(Me.FormView1.FindControl("Case_IDLabel"), Label).Text.ToString
-
Dim FormRef As String = CType(Me.FormView1.FindControl("Form_IDLabel"), Label).Text.ToString
-
Response.Redirect("~/logged_in/success.aspx?Form_ID=" & FormRef & "&Case_ID=" & CaseRef, False)
-
-
Catch ex As Exception
-
Response.Redirect("~/GenericErrorPage.aspx", False)
-
-
End Try
-
-
End Sub
-
-
Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
-
'Assign value to textbox from Calendar
-
CType(Me.FormView1.FindControl("BF_DateTextBox"), TextBox).Text = CType(Me.FormView1.FindControl("Calendar1"), Calendar).SelectedDate.AddDays(7).ToString("dd/MM/yyyy")
-
CType(Me.FormView1.FindControl("Date_Issued"), TextBox).Text = CType(Me.FormView1.FindControl("Calendar1"), Calendar).SelectedDate.ToString("dd/MM/yyyy")
-
End Sub
-
-
Protected Sub Calendar2_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
-
'Assign value to textbox from Calendar
-
CType(Me.FormView1.FindControl("Returned_DateTextBox"), TextBox).Text = CType(Me.FormView1.FindControl("Calendar2"), Calendar).SelectedDate.ToString("dd/MM/yyyy")
-
End Sub
-
-
Protected Sub Calendar3_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
-
'Assign value to textbox from Calendar
-
CType(Me.FormView1.FindControl("BF_DateTextBox"), TextBox).Text = CType(Me.FormView1.FindControl("Calendar3"), Calendar).SelectedDate.ToString("dd/MM/yyyy")
-
End Sub
-
-
Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
-
' Switches between hiding and showing the calendar
-
If Me.FormView1.FindControl("Calendar1").Visible = "false" Then
-
Me.FormView1.FindControl("Calendar1").Visible = "true"
-
Else
-
Me.FormView1.FindControl("Calendar1").Visible = "false"
-
End If
-
End Sub
-
Protected Sub ImageButton2_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
-
' Switches between hiding and showing the calendar
-
If Me.FormView1.FindControl("Calendar2").Visible = "false" Then
-
Me.FormView1.FindControl("Calendar2").Visible = "true"
-
Else
-
Me.FormView1.FindControl("Calendar2").Visible = "false"
-
End If
-
End Sub
-
-
Protected Sub ImageButton3_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
-
' Switches between hiding and showing the calendar
-
If Me.FormView1.FindControl("Calendar3").Visible = "false" Then
-
Me.FormView1.FindControl("Calendar3").Visible = "true"
-
Else
-
Me.FormView1.FindControl("Calendar3").Visible = "false"
-
End If
-
End Sub
-
-
Public Sub Page_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
'Try
-
-
If Not Page.IsPostBack Then
-
If Request.QueryString("update") = "yes" Then
-
'Test if update requested
-
Me.FormView1.DefaultMode = FormViewMode.Edit
-
Dim sqlConnection1 As New Data.SqlClient.SqlConnection(Me.SqlDataSource1.ConnectionString)
-
Dim cmd As New Data.SqlClient.SqlCommand
-
Dim case_id As String
-
Dim form_id As String
-
case_id = Request.QueryString("case_id")
-
form_id = Request.QueryString("form_id")
-
-
'this dim used in selecting case_link_id
-
' Dim singleReturn As New Data.SqlClient.SqlParameter("@SingleReturn", Data.SqlDbType.Int)
-
Dim singleReturn As New Data.SqlClient.SqlParameter("@RETURN VALUE", Data.SqlDbType.Int)
-
-
-
'these dims used in select for entire record
-
Dim thisCaseID As New Data.SqlClient.SqlParameter("@thisCaseID", Data.SqlDbType.Int)
-
Dim thisFormID As New Data.SqlClient.SqlParameter("@thisFormID", Data.SqlDbType.Int)
-
Dim thisDateIssued As New Data.SqlClient.SqlParameter("@thisDateIssued", Data.SqlDbType.DateTime)
-
Dim thisBFDate As New Data.SqlClient.SqlParameter("@thisBFDate", Data.SqlDbType.DateTime)
-
Dim thisReturnedDate As New Data.SqlClient.SqlParameter("@thisReturnedDate", Data.SqlDbType.DateTime)
-
Dim thisNA As New Data.SqlClient.SqlParameter("@thisNA", Data.SqlDbType.Bit)
-
Dim thisNotes As New Data.SqlClient.SqlParameter("@thisNotes", Data.SqlDbType.VarChar)
-
Dim thisValue As Integer
-
-
sqlConnection1.Open()
-
singleReturn.Direction = Data.ParameterDirection.ReturnValue
-
With cmd
-
' gets case_link_id
-
.CommandText = "getSingleValue"
-
.CommandType = Data.CommandType.StoredProcedure
-
.Parameters.AddWithValue("@case_id", case_id)
-
.Parameters.AddWithValue("@form_id", form_id)
-
' .Parameters.AddWithValue("@SingleReturn", 0)
-
'.Parameters.Add(singleReturn).Direction = Data.ParameterDirection.Output
-
'.Parameters.Add(singleReturn).Direction = Data.ParameterDirection.ReturnValue
-
.Parameters.Add(singleReturn)
-
.Connection = sqlConnection1
-
.ExecuteNonQuery()
-
-
End With
-
thisValue = singleReturn.Value
-
CType(Me.FormView1.FindControl("lblCaseLinkID"), Label).Text = thisValue.ToString
-
-
sqlConnection1.Close()
-
-
'Create a New Connection for the Stored Procedure
-
Dim myConnection As New Data.SqlClient.SqlConnection(Me.SqlDataSource1.ConnectionString)
-
myConnection.Open()
-
-
Dim strSQL As String
-
strSQL = "SELECT * FROM tbl_Forms_Case_Link WHERE Form_Case_Link_ID = " & thisValue
-
Dim myCommand As New Data.SqlClient.SqlCommand(strSQL, myConnection)
-
myCommand.CommandType = Data.CommandType.Text
-
Dim dr As Data.SqlClient.SqlDataReader = myCommand.ExecuteReader()
-
Dim arrayForms As New ArrayList()
-
Dim i As Integer
-
i = 0
-
i = dr.FieldCount()
-
'fill array with database fields
-
If dr.HasRows Then
-
While dr.Read()
-
For i = 0 To dr.FieldCount - 1
-
arrayForms.Add(dr.Item(i))
-
Next
-
End While
-
End If
-
-
dr.Close()
-
-
myConnection.Close()
-
'populate form fields from array of fields
-
CType(Me.FormView1.FindControl("Date_Issued"), TextBox).Text = arrayForms.Item(3).ToShortDateString
-
CType(Me.FormView1.FindControl("Calendar1"), Calendar).SelectedDate = arrayForms.Item(3)
-
CType(Me.FormView1.FindControl("BF_DateTextBox"), TextBox).Text = arrayForms.Item(4).ToShortDateString
-
-
If arrayForms.Item(5) IsNot DBNull.Value Then
-
CType(Me.FormView1.FindControl("Returned_DateTextBox"), TextBox).Text = arrayForms.Item(5).ToShortDateString
-
-
-
End If
-
-
CType(Me.FormView1.FindControl("NA"), CheckBox).Checked = arrayForms.Item(6)
-
-
CType(Me.FormView1.FindControl("NotesTextBox"), TextBox).Text = arrayForms.Item(7).ToString
-
-
-
Else
-
If Not Page.IsPostBack Then
-
'pre-populate date fields and calendar
-
CType(Me.FormView1.FindControl("Date_Issued"), TextBox).Text = Date.Now.ToString("dd/MM/yyyy")
-
CType(Me.FormView1.FindControl("BF_DateTextBox"), TextBox).Text = Date.Now.AddDays(7).ToString("dd/MM/yyyy")
-
CType(Me.FormView1.FindControl("Calendar1"), Calendar).SelectedDate = CType(Me.FormView1.FindControl("Date_Issued"), TextBox).Text
-
-
End If
-
-
If Page.IsPostBack Then
-
'fill BF Date information automatically
-
CType(Me.FormView1.FindControl("BF_DateTextBox"), TextBox).Text = Convert.ToDateTime(CType(Me.FormView1.FindControl("Date_Issued"), TextBox).Text).Date.AddDays(7).ToShortTimeString("dd/MM/yyyy")
-
CType(Me.FormView1.FindControl("Calendar1"), Calendar).SelectedDate = Convert.ToDateTime(CType(Me.FormView1.FindControl("Date_Issued"), TextBox).Text).Date.AddDays(7).ToString("dd/MM/yyyy")
-
-
End If
-
End If
-
End If
-
' Catch ex As Exception
-
'Response.Redirect("~/GenericErrorPage.aspx", False)
-
-
'End Try
-
End Sub
-
-
Protected Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
-
Try
-
'Create a New Connection for the Stored Procedure
-
Dim myConnection As New Data.SqlClient.SqlConnection(Me.SqlDataSource1.ConnectionString)
-
Data.SqlClient.SqlConnection.ClearAllPools()
-
myConnection.Open()
-
'Setup SQLCommand for UPDATE statement from SQLDataSource1
-
Dim myCommand As New Data.SqlClient.SqlCommand("UPDATE_FORM", myConnection)
-
myCommand.CommandType = Data.CommandType.StoredProcedure
-
Dim param2 As Date
-
-
'Try Catch statement for testing Returned_Date value
-
Try
-
param2 = Convert.ToDateTime(CType(Me.FormView1.FindControl("Returned_DateTextBox"), TextBox).Text.ToString)
-
myCommand.Parameters.AddWithValue("@Returned_Date", param2)
-
Catch ex As Exception
-
myCommand.Parameters.AddWithValue("@Returned_Date", DBNull.Value)
-
-
End Try
-
-
'Add the rest of the insert parameters
-
myCommand.Parameters.AddWithValue("@form_case_link_id", CType(Me.FormView1.FindControl("lblCaseLinkID"), Label).Text)
-
-
myCommand.Parameters.AddWithValue("@date_issued", Convert.ToDateTime(CType(Me.FormView1.FindControl("date_issued"), TextBox).Text))
-
-
myCommand.Parameters.AddWithValue("@bf_date", Convert.ToDateTime(CType(Me.FormView1.FindControl("bf_dateTextBox"), TextBox).Text))
-
-
myCommand.Parameters.AddWithValue("@NA", CType(Me.FormView1.FindControl("NA"), CheckBox).Checked)
-
-
myCommand.Parameters.AddWithValue("@Notes", CType(Me.FormView1.FindControl("NotesTextBox"), TextBox).Text)
-
-
'Execute the command
-
'Dim reader As Data.SqlClient.SqlDataReader = myCommand.ExecuteReader
-
myCommand.ExecuteReader()
-
myConnection.Close()
-
-
'build redirect url
-
Dim CaseRef As String = CType(Me.FormView1.FindControl("Case_IDLabel"), Label).Text.ToString
-
Dim FormRef As String = CType(Me.FormView1.FindControl("Form_IDLabel"), Label).Text.ToString
-
Response.Redirect("~/logged_in/update_success.aspx?Form_ID=" & FormRef & "&Case_ID=" & CaseRef, False)
-
-
Catch ex As Exception
-
Response.Redirect("~/GenericErrorPage.aspx", False)
-
-
End Try
-
End Sub
-
-
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
-
'clears returned date checkbox
-
CType(Me.FormView1.FindControl("Returned_DateTextBox"), TextBox).Text = ""
-
Me.FormView1.FindControl("Calendar2").Visible = "false"
-
End Sub
-
End Class
-
-
Form -
-
<%@ Page Language="VB" MasterPageFile="~/logged_in/MasterPage.master" AutoEventWireup="false" CodeFile="ESA55pbc.aspx.vb" Inherits="css_ESA55pbc" title="MAID - ESA55pbc" %>
-
<asp:Content ID="Content1" ContentPlaceHolderID="pageTitle" Runat="Server">
-
ESA55pbc
-
</asp:Content>
-
<asp:Content ID="Content2" ContentPlaceHolderID="mainContent" Runat="Server">
-
<asp:FormView DefaultMode="Insert" ID="FormView1" runat="server" DataKeyNames="Form_Case_Link_ID"
-
DataSourceID="SqlDataSource1" Width="666px">
-
<EditItemTemplate>
-
<h3>
-
Update Form - <%Response.write(Session("nino").ToString) %></h3>
-
<br />
-
-
<asp:Label ID="lblCaseLinkID" runat="server" Text="Label"></asp:Label><br />
-
<span class="form_header">Case ID:</span>
-
<asp:Label ID="Case_IDLabel" runat="server" Text='<%# Request.QueryString("Case_ID") %>'></asp:Label><br />
-
<span class="form_header">Form ID:</span>
-
<asp:Label ID="Form_IDLabel" runat="server" Text='<%# Request.QueryString("form_ID") %>'></asp:Label><br />
-
<br><span class="form_header">Date Issued:</span>
-
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/calendar.gif"
-
OnClick="ImageButton1_Click" AlternateText="Calendar Button - Click to show date picker" ToolTip="Click to show date picker" />
-
<asp:Calendar ID="Calendar1" Visible="false" runat="server" SelectedDate='<%# Bind("Date_Issued") %>' OnSelectionChanged="Calendar1_SelectionChanged" CssClass="table-align">
-
</asp:Calendar>
-
<br/>
-
<br/><span class="form_header">Date Selected:</span><asp:TextBox ID="Date_Issued" runat="server" AutoPostBack="True" ReadOnly="True" ></asp:TextBox>
-
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="Date_Issued"
-
Display="Dynamic" ErrorMessage="RequiredFieldValidator">You must have a date issued</asp:RequiredFieldValidator>
-
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="Date_Issued"
-
Display="Dynamic" ErrorMessage="Date must be in the format dd/mm/yyyy" ValidationExpression="(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2}"></asp:RegularExpressionValidator><br />
-
<br />
-
-
<br><span class="form_header">BF Date:</span>
-
<asp:ImageButton ID="ImageButton3" runat="server" ImageUrl="~/images/calendar.gif"
-
OnClick="ImageButton3_Click" AlternateText="Calendar Button - Click to show date picker" ToolTip="Click to show date picker" />
-
<asp:Calendar ID="Calendar3" Visible="false" runat="server" SelectedDate='<%# Bind("Date_Issued") %>' OnSelectionChanged="Calendar3_SelectionChanged" CssClass="table-align" CellPadding="0" CellSpacing="1">
-
<TitleStyle BackColor="#326171" ForeColor="#FFF2B3" Font-Bold="True" HorizontalAlign="Center" CssClass="angles" />
-
<SelectedDayStyle BackColor="#EEEEEE" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px"
-
ForeColor="Black" />
-
<TodayDayStyle BackColor="#FFFFC0" BorderColor="Gray" BorderStyle="Solid" BorderWidth="1px"
-
ForeColor="Black" />
-
<WeekendDayStyle BackColor="#EEEEEE" />
-
<OtherMonthDayStyle BackColor="White" />
-
<NextPrevStyle ForeColor="#FFF2B3" HorizontalAlign="Center" />
-
</asp:Calendar>
-
<br/>
-
<br><span class="form_header">Date Selected:</span>
-
<asp:TextBox ID="BF_DateTextBox" runat="server" ReadOnly="True" ></asp:TextBox><br/>
-
<br/><span class="form_header">Returned Date:</span>
-
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/images/calendar.gif"
-
OnClick="ImageButton2_Click" AlternateText="Calendar Button - Click to show date picker" ToolTip="Click to show date picker" />
-
<asp:Calendar ID="Calendar2" CssClass="table-align" Visible="false" runat="server" OnSelectionChanged="Calendar2_SelectionChanged">
-
<TitleStyle BackColor="#326171" ForeColor="#FFF2B3" Font-Bold="True" HorizontalAlign="Center" CssClass="angles" />
-
<SelectedDayStyle BackColor="#EEEEEE" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px"
-
ForeColor="Black" />
-
<TodayDayStyle BackColor="#FFFFC0" BorderColor="Gray" BorderStyle="Solid" BorderWidth="1px"
-
ForeColor="Black" />
-
<WeekendDayStyle BackColor="#EEEEEE" />
-
<OtherMonthDayStyle BackColor="White" />
-
<NextPrevStyle ForeColor="#FFF2B3" HorizontalAlign="Center" />
-
</asp:Calendar>
-
<br><span class="form_header">Date Selected:</span>
-
<asp:TextBox ID="Returned_DateTextBox" runat="server"></asp:TextBox>
-
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Clear Date Selected</asp:LinkButton>
-
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="Returned_DateTextBox"
-
Display="Dynamic" ErrorMessage="Date must be in the format dd/mm/yyyy" ValidationExpression="(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2}"></asp:RegularExpressionValidator><br />
-
<br><span class="form_header">NA:</span>
-
<asp:CheckBox ID="NA" runat="server" TextAlign="Left" /><br />
-
<span class="form_header">Notes:</span>
-
<asp:TextBox ID="NotesTextBox" runat="server" Height="146px" MaxLength="250" Text='<%# Bind("Notes") %>'
-
TextMode="MultiLine" Width="292px"></asp:TextBox><br />
-
<br><asp:Button ID="Submit" runat="server" CommandName="Update" OnClick="Submit_Click"
-
Text="Update" />
-
<br />
-
<br />
-
<a href="case_Details.aspx?case_id=<%Response.write(Request.QueryString("Case_ID").ToString) %>&NINO=<%Response.write(Session("nino").ToString) %>">Back to Case Details for NINO: <%Response.Write(Session("nino").ToString)%> </a>
-
-
</EditItemTemplate>
-
<InsertItemTemplate>
-
<h3>
-
Insert Form - <%Response.write(Session("nino").ToString) %></h3>
-
<br />
-
<asp:Label ID="lblCaseLinkID" runat="server" Text="Label"></asp:Label><br />
-
<span class="form_header">Case ID:</span>
-
<asp:Label ID="Case_IDLabel" runat="server" Text='<%# Request.QueryString("Case_ID") %>'></asp:Label><br />
-
<span class="form_header">Form ID:</span>
-
<asp:Label ID="Form_IDLabel" runat="server" Text='<%# Request.QueryString("form_ID") %>'></asp:Label><br />
-
<br/>
-
<span class="form_header">Date Issued: </span>
-
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/calendar.gif"
-
OnClick="ImageButton1_Click" AlternateText="Calendar Button - Click to show date picker" ToolTip="Click to show date picker" />
-
<asp:Calendar ID="Calendar1" Visible="false" runat="server" SelectedDate='<%# Bind("Date_Issued") %>' OnSelectionChanged="Calendar1_SelectionChanged" CssClass="table-align" CellPadding="0" CellSpacing="1">
-
<TitleStyle BackColor="#326171" ForeColor="#FFF2B3" Font-Bold="True" HorizontalAlign="Center" CssClass="angles" />
-
<SelectedDayStyle BackColor="#EEEEEE" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px"
-
ForeColor="Black" />
-
<TodayDayStyle BackColor="#FFFFC0" BorderColor="Gray" BorderStyle="Solid" BorderWidth="1px"
-
ForeColor="Black" />
-
<WeekendDayStyle BackColor="#EEEEEE" />
-
<OtherMonthDayStyle BackColor="White" />
-
<NextPrevStyle ForeColor="#FFF2B3" HorizontalAlign="Center" />
-
</asp:Calendar>
-
<br/>
-
-
<span class="form_header">Date Selected:</span>
-
<asp:TextBox ID="Date_Issued" runat="server" AutoPostBack="True" ReadOnly="True" ></asp:TextBox>
-
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="Date_Issued"
-
ErrorMessage="RequiredFieldValidator" Display="Dynamic">You must have a date issued</asp:RequiredFieldValidator>
-
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="Date_Issued"
-
Display="Dynamic" ErrorMessage="Date must be in the format dd/mm/yyyy" ValidationExpression="(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2}"></asp:RegularExpressionValidator><br />
-
<br />
-
<span class="form_header">BF Date:</span>
-
<asp:ImageButton ID="ImageButton3" runat="server" ImageUrl="~/images/calendar.gif"
-
OnClick="ImageButton3_Click" AlternateText="Calendar Button - Click to show date picker" ToolTip="Click to show date picker" />
-
<asp:Calendar ID="Calendar3" Visible="false" runat="server" SelectedDate='<%# Bind("Date_Issued") %>' OnSelectionChanged="Calendar3_SelectionChanged" CssClass="table-align" CellPadding="0" CellSpacing="1">
-
<TitleStyle BackColor="#326171" ForeColor="#FFF2B3" Font-Bold="True" HorizontalAlign="Center" CssClass="angles" />
-
<SelectedDayStyle BackColor="#EEEEEE" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px"
-
ForeColor="Black" />
-
<TodayDayStyle BackColor="#FFFFC0" BorderColor="Gray" BorderStyle="Solid" BorderWidth="1px"
-
ForeColor="Black" />
-
<WeekendDayStyle BackColor="#EEEEEE" />
-
<OtherMonthDayStyle BackColor="White" />
-
<NextPrevStyle ForeColor="#FFF2B3" HorizontalAlign="Center" />
-
</asp:Calendar>
-
<br/>
-
<br><span class="form_header">Date Selected:</span>
-
<asp:TextBox ID="BF_DateTextBox" runat="server" ReadOnly="True" ></asp:TextBox><br/>
-
<br/><span class="form_header">Returned Date:</span>
-
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/images/calendar.gif"
-
OnClick="ImageButton2_Click" AlternateText="Calendar Button - Click to show date picker" ToolTip="Click to show date picker" />
-
<asp:Calendar ID="Calendar2" Visible="false" runat="server" SelectedDate='<%# Bind("Returned_Date") %>' OnSelectionChanged="Calendar2_SelectionChanged" CssClass="table-align" CellPadding="0" CellSpacing="1">
-
<TitleStyle BackColor="#326171" ForeColor="#FFF2B3" Font-Bold="True" HorizontalAlign="Center" CssClass="angles" />
-
<SelectedDayStyle BackColor="#EEEEEE" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px"
-
ForeColor="Black" />
-
<TodayDayStyle BackColor="#FFFFC0" BorderColor="Gray" BorderStyle="Solid" BorderWidth="1px"
-
ForeColor="Black" />
-
<WeekendDayStyle BackColor="#EEEEEE" />
-
<OtherMonthDayStyle BackColor="White" />
-
<NextPrevStyle ForeColor="#FFF2B3" HorizontalAlign="Center" />
-
</asp:Calendar>
-
<br/>
-
<span class="form_header">Date Selected:</span>
-
<asp:TextBox ID="Returned_DateTextBox" runat="server" Text='<%# Bind("Returned_Date") %>' ReadOnly="True" ></asp:TextBox>
-
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Clear Date Selected</asp:LinkButton>
-
<asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ControlToValidate="Returned_DateTextBox"
-
Display="Dynamic" ErrorMessage="Date must be in the format dd/mm/yyyy" ValidationExpression="(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2}"></asp:RegularExpressionValidator><br />
-
<br/>
-
<span class="form_header">NA:</span><asp:CheckBox ID="NA" runat="server" Checked='<%# Bind("NA") %>' TextAlign="Left" /><br />
-
<span class="form_header">Notes:</span>
-
<asp:TextBox ID="NotesTextBox" runat="server" Text='<%# Bind("Notes") %>' Height="146px" MaxLength="250" TextMode="MultiLine" Width="292px"></asp:TextBox><br />
-
<br/>
-
<asp:Button ID="InsertButton" runat="server" CausesValidation="True"
-
Text="Insert" OnClick="InsertButton_Click1"></asp:Button>
-
<br />
-
<br />
-
<a href="case_Details.aspx?case_id=<%Response.write(Request.QueryString("Case_ID").ToString) %>&NINO=<%Response.write(Session("nino").ToString) %>">Back to Case Details for NINO: <%Response.Write(Session("nino").ToString)%> </a>
-
-
</InsertItemTemplate>
-
<ItemTemplate>
-
Form_Case_Link_ID:
-
<asp:Label ID="Form_Case_Link_IDLabel" runat="server" Text='<%# Eval("Form_Case_Link_ID") %>'></asp:Label><br />
-
Case_ID:
-
<asp:Label ID="Case_IDLabel" runat="server" Text='<%# Bind("Case_ID") %>'></asp:Label><br />
-
Form_ID:
-
<asp:Label ID="Form_IDLabel" runat="server" Text='<%# Bind("Form_ID") %>'></asp:Label><br />
-
Date_Issued:
-
<asp:Label ID="Date_IssuedLabel" runat="server" Text='<%# Bind("Date_Issued") %>'></asp:Label><br />
-
BF_Date:
-
<asp:Label ID="BF_DateLabel" runat="server" Text='<%# Bind("BF_Date") %>'></asp:Label><br />
-
Returned_Date:
-
<asp:Label ID="Returned_DateLabel" runat="server" Text='<%# Bind("Returned_Date") %>'></asp:Label><br />
-
NA:
-
<asp:Label ID="NALabel" runat="server" Text='<%# Bind("NA") %>'></asp:Label><br />
-
Notes:
-
<asp:Label ID="NotesLabel" runat="server" Text='<%# Bind("Notes") %>'></asp:Label><br />
-
</ItemTemplate>
-
</asp:FormView>
-
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ESA_TrackerConnectionString %>"
-
SelectCommand="SELECT * FROM [tbl_Forms_Case_Link]" UpdateCommand="UPDATE_FORM" DeleteCommand="DELETE FROM [tbl_Forms_Case_Link] WHERE [Form_Case_Link_ID] = @Form_Case_Link_ID" InsertCommand="INSERT INTO [tbl_Forms_Case_Link] ([Case_ID], [Form_ID], [Date_Issued], [BF_Date], [Returned_Date], [NA], [Notes]) VALUES (@Case_ID, @Form_ID, @Date_Issued, @BF_Date, @Returned_Date, @NA, @Notes)" UpdateCommandType="StoredProcedure">
-
<UpdateParameters>
-
<asp:Parameter Direction="ReturnValue" Name="RETURN_VALUE" Type="Int32" />
-
<asp:Parameter Name="form_case_link_id" Type="Int32" />
-
<asp:Parameter Name="date_issued" Type="DateTime" />
-
<asp:Parameter Name="bf_date" Type="DateTime" />
-
<asp:Parameter Name="Returned_Date" Type="DateTime" />
-
<asp:Parameter Name="NA" Type="Boolean" />
-
<asp:Parameter Name="Notes" Type="String" />
-
</UpdateParameters>
-
<DeleteParameters>
-
<asp:Parameter Name="Form_Case_Link_ID" Type="Int32" />
-
</DeleteParameters>
-
<InsertParameters>
-
<asp:Parameter Name="Case_ID" Type="Int32" />
-
<asp:Parameter Name="Form_ID" Type="Int32" />
-
<asp:Parameter Name="Date_Issued" Type="DateTime" />
-
<asp:Parameter Name="BF_Date" Type="DateTime" />
-
<asp:Parameter Name="Returned_Date" Type="DateTime" />
-
<asp:Parameter Name="NA" Type="Boolean" />
-
<asp:Parameter Name="Notes" Type="String" />
-
</InsertParameters>
-
</asp:SqlDataSource>
-
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ESA_TrackerConnectionString %>"
-
SelectCommand="getSingleValue" SelectCommandType="StoredProcedure" >
-
<SelectParameters>
-
<asp:QueryStringParameter Name="Case_ID" QueryStringField="case_id" Type="Int32" />
-
<asp:QueryStringParameter Name="Form_ID" QueryStringField="form_id" Type="Int32" />
-
<asp:Parameter Direction="InputOutput" Name="SingleReturn" Type="Int32" />
-
</SelectParameters>
-
</asp:SqlDataSource>
-
-
</asp:Content>
-
-
-
-
SET ANSI_NULLS ON
-
SET QUOTED_IDENTIFIER ON
-
go
-
-
-
-
-
-
-
ALTER PROCEDURE [dbo].[GetSingleValue]
-
@Case_ID int,
-
@Form_ID int
-
--@SingleReturn int OUTPUT,
-
-
AS
-
DECLARE @rc int
-
-
--SELECT @SingleReturn = Form_Case_Link_ID
-
--SELECT Form_Case_Link_ID
-
SELECT @rc = Form_Case_Link_ID
-
FROM tbl_Forms_Case_Link
-
WHERE (Case_ID = @Case_ID) AND (Form_ID = @Form_ID)
-
-
--SET @SingleReturn = Form_Case_Link_ID
-
-
RETURN @rc
-
-
|  | Site Moderator | | Join Date: Oct 2006 Location: The Great White North
Posts: 5,137
| | | re: strange update problem .net
In the future it might be a good idea just to post the code that you think is causing the problem instead of everything. It's hard to read through a lot of code to just to find the function(s) that you are having problems....It makes it especially hard to understand when you have buttons named like "Submit" and "LinkButton1"...I'm not sure what these buttons are supposed to actually be doing.
Anyways, your Submit button seems to have code for handling your table update...however your page load event also seems to be doing something with your table. One of these methods could be updating the wrong thing.
-Frinny
|  | Moderator | | Join Date: Apr 2007 Location: New England
Posts: 7,161
| | | re: strange update problem .net
Avoiding for now that your page_load() looks like it is doing something fishy and is likely the culprit...
I don't see your actual update procedure, just an sql function that could select multiple results, but you only return one.
In my StoredProcedures that do updates, I frequently will include a count() to determine the number of records effected.
For isntance a snippit might be: -
SELECT
-
@RowsAffected=count(*)
-
FROM
-
[Assemblies]
-
WHERE
-
[AssemblyID] = @AssemblyID;
-
-
--do update
-
UPDATE
-
[Assemblies]
-
SET
-
[LaborHours] = @LaborHours
-
,[Notes] = @Notes
-
,[ModifiedDate] = @ModifiedDate
-
WHERE
-
[AssemblyID] = @AssemblyID;
-
-
RETURN @RowsAffected;
-
|  | Similar .NET Framework bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,510 network members.
|