Im working using Gridview and Sqldatasource, so , when Im tried to use the updatecommand, but when I clicked on, nothing happen, so, if I save a new record and after click on update command button , so , it works well. do you have any idea about whats happening ?
the next is my code snipped
<asp:GridView ID="gvInfoCobradores" runat="server" CellPadding="4"
ForeColor="#333333" GridLines="None" AutoGenerateEditButton="True"
OnRowEditing="gvInfoAdmin_RowEditing" OnRowUpdating="gvInfoAdmin_RowUpdating"
DataSourceID="dsCobradorInfo" DataKeyNames="ID_Cobrador" Width="50%">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ShowDeleteButton="True" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
</asp:GridView>
<asp:SqlDataSource ID="dsCobradorInfo" runat="server" ConnectionString="<%$ ConnectionStrings:SeminarioConnectionString %>"
SelectCommand="SELECT * FROM [UsuariosSistema].[Cobrador]"
OldValuesParameterFormatString="original_{0}" ConflictDetection="CompareAllValues"
DeleteCommand="DELETE FROM [UsuariosSistema].[Cobrador] WHERE [ID_Cobrador] = #original_ID_Cobrador AND [NombreUsuarioCobrador] = #original_NombreUsuarioCobrador AND [PasswordCobrador] = #original_PasswordCobrador AND [NombreCobrador] = #original_NombreCobrador AND [ApellidoPaternoCobrador] = #original_ApellidoPaternoCobrador AND [ApellidoMaternoCobrador] = #original_ApellidoMaternoCobrador AND (([TelCobrador] = #original_TelCobrador) OR ([TelCobrador] IS NULL AND #original_TelCobrador IS NULL)) AND (([CelCobrador] = #original_CelCobrador) OR ([CelCobrador] IS NULL AND #original_CelCobrador IS NULL)) AND (([CorreElectronicoCobrador] = #original_CorreElectronicoCobrador) OR ([CorreElectronicoCobrador] IS NULL AND #original_CorreElectronicoCobrador IS NULL))"
InsertCommand="INSERT INTO [UsuariosSistema].[Cobrador] ([NombreUsuarioCobrador], [PasswordCobrador], [NombreCobrador], [ApellidoPaternoCobrador], [ApellidoMaternoCobrador], [TelCobrador], [CelCobrador], [CorreElectronicoCobrador]) VALUES (#NombreUsuarioCobrador, #PasswordCobrador, #NombreCobrador, #ApellidoPaternoCobrador, #ApellidoMaternoCobrador, #TelCobrador, #CelCobrador, #CorreElectronicoCobrador)"
UpdateCommand="UPDATE [UsuariosSistema].[Cobrador] SET [NombreUsuarioCobrador] = #NombreUsuarioCobrador, [PasswordCobrador] = #PasswordCobrador, [NombreCobrador] = #NombreCobrador, [ApellidoPaternoCobrador] = #ApellidoPaternoCobrador, [ApellidoMaternoCobrador] = #ApellidoMaternoCobrador, [TelCobrador] = #TelCobrador, [CelCobrador] = #CelCobrador, [CorreElectronicoCobrador] = #CorreElectronicoCobrador WHERE [ID_Cobrador] = #original_ID_Cobrador AND [NombreUsuarioCobrador] = #original_NombreUsuarioCobrador AND [PasswordCobrador] = #original_PasswordCobrador AND [NombreCobrador] = #original_NombreCobrador AND [ApellidoPaternoCobrador] = #original_ApellidoPaternoCobrador AND [ApellidoMaternoCobrador] = #original_ApellidoMaternoCobrador AND (([TelCobrador] = #original_TelCobrador) OR ([TelCobrador] IS NULL AND #original_TelCobrador IS NULL)) AND (([CelCobrador] = #original_CelCobrador) OR ([CelCobrador] IS NULL AND #original_CelCobrador IS NULL)) AND (([CorreElectronicoCobrador] = #original_CorreElectronicoCobrador) OR ([CorreElectronicoCobrador] IS NULL AND #original_CorreElectronicoCobrador IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_ID_Cobrador" Type="Int32" />
<asp:Parameter Name="original_NombreUsuarioCobrador" Type="String" />
<asp:Parameter Name="original_PasswordCobrador" Type="String" />
<asp:Parameter Name="original_NombreCobrador" Type="String" />
<asp:Parameter Name="original_ApellidoPaternoCobrador" Type="String" />
<asp:Parameter Name="original_ApellidoMaternoCobrador" Type="String" />
<asp:Parameter Name="original_TelCobrador" Type="String" />
<asp:Parameter Name="original_CelCobrador" Type="String" />
<asp:Parameter Name="original_CorreElectronicoCobrador" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="NombreUsuarioCobrador" Type="String" />
<asp:Parameter Name="PasswordCobrador" Type="String" />
<asp:Parameter Name="NombreCobrador" Type="String" />
<asp:Parameter Name="ApellidoPaternoCobrador" Type="String" />
<asp:Parameter Name="ApellidoMaternoCobrador" Type="String" />
<asp:Parameter Name="TelCobrador" Type="String" />
<asp:Parameter Name="CelCobrador" Type="String" />
<asp:Parameter Name="CorreElectronicoCobrador" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="NombreUsuarioCobrador" Type="String" />
<asp:Parameter Name="PasswordCobrador" Type="String" />
<asp:Parameter Name="NombreCobrador" Type="String" />
<asp:Parameter Name="ApellidoPaternoCobrador" Type="String" />
<asp:Parameter Name="ApellidoMaternoCobrador" Type="String" />
<asp:Parameter Name="TelCobrador" Type="String" />
<asp:Parameter Name="CelCobrador" Type="String" />
<asp:Parameter Name="CorreElectronicoCobrador" Type="String" />
<asp:Parameter Name="original_ID_Cobrador" Type="Int32" />
<asp:Parameter Name="original_NombreUsuarioCobrador" Type="String" />
<asp:Parameter Name="original_PasswordCobrador" Type="String" />
<asp:Parameter Name="original_NombreCobrador" Type="String" />
<asp:Parameter Name="original_ApellidoPaternoCobrador" Type="String" />
<asp:Parameter Name="original_ApellidoMaternoCobrador" Type="String" />
<asp:Parameter Name="original_TelCobrador" Type="String" />
<asp:Parameter Name="original_CelCobrador" Type="String" />
<asp:Parameter Name="original_CorreElectronicoCobrador" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
Thanks in advance!!
Related
I have a problem that I couldn't find a solution for.
As seen in the picture below, i have a gridView to display list of events. what i want is to compare "eventEndDate" column values with the current day, in order to update the last column rows, "eventStatus".
So, I added a while loop to read through the database and get the values of "EventEndDate" as the following:
while (reader.Read())
{
result.Add(reader.GetValue(4).ToString());
}
reader.Close();
Then, within the load method also I added these codes:
string currentDate = DateTime.Now.ToString("MMMM/d/yyyy");
//endDate = DateTime.Now.ToString("MMMM/d/yyyy");
//TextBox1.Text = Session["CountryName"].ToString();
country = Session["CountryName"].ToString();
SqlDataSource1.SelectCommand = "SELECT * FROM EventsEnglish WHERE CountryName ='" + country + "'";
SqlDataSource1.DataBind();
foreach (var lastDay in result)
{
string lastDayDate = Convert.ToDateTime(lastDay).ToString("MMMM/d/yyyy");
if (DateTime.ParseExact(lastDayDate, "MMMM/d/yyyy", CultureInfo.InvariantCulture) > DateTime.ParseExact(currentDate, "MMMM/d/yyyy", CultureInfo.InvariantCulture))
{
SqlDataSource1.UpdateCommand = "UPDATE EventsEnglish SET EventStatus = Open";
SqlDataSource1.DataBind();
}
else
{
SqlDataSource1.UpdateCommand = "UPDATE EventsEnglish SET EventStatus = Close";
SqlDataSource1.DataBind();
}
the problem is, I don't get any error messages but the event status doesn't update ...
So, what is i'm doing wrong???
please use ExecuteNonQuery() to update your table.
I am doing the same thing for a project. I use this type of c# grid connecting to sql server and the updates works fine, (you only have to change the boundfield values, the sql command for the update and the parameters for the update.
<body>
<form id="form1" runat="server">
<div style="height: 300px">
<asp:Button CssClass="btn btn-primary" ID="btn_back_to_admin" runat="server" Text="Back to Admin" OnClick="btn_back_to_admin_Click" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="ID" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" Height="260px" style="margin-bottom: 116px">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Nombre" HeaderText="Nombre" SortExpression="Nombre" />
<asp:BoundField DataField="Precio" HeaderText="Precio" SortExpression="Precio" />
<asp:BoundField DataField="Codigo" HeaderText="Codigo" SortExpression="Codigo" />
<asp:BoundField DataField="Garantia" HeaderText="Garantia" SortExpression="Garantia" />
<asp:BoundField DataField="Marca" HeaderText="Marca" SortExpression="Marca" />
<asp:BoundField DataField="AspectosTecnicos" HeaderText="AspectosTecnicos" SortExpression="AspectosTecnicos" />
<asp:BoundField DataField="Fotografia1" HeaderText="Fotografia" SortExpression="Fotografia1" />
<asp:BoundField DataField="Descripcion" HeaderText="Descripcion" SortExpression="Descripcion" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ShoppingConnectionString %>" DeleteCommand="DELETE FROM [main_product] WHERE [P_ID] = #P_ID" InsertCommand="INSERT INTO [main_product] ([Product_name], [MRP], [Our_Prize], [Discount], [Brand], [Brand_image], [Type_of_product], [Imagepath1], [Imagepath2], [Imagepath3], [Imagepath4], [Detail], [stock], [new_arrival], [best_seller], [best_offer]) VALUES (#Product_name, #MRP, #Our_Prize, #Discount, #Brand, #Brand_image, #Type_of_product, #Imagepath1, #Imagepath2, #Imagepath3, #Imagepath4, #Detail, #stock, #new_arrival, #best_seller, #best_offer)" SelectCommand="SELECT * FROM [FO_Productos]" UpdateCommand=" Exec FOSP_ActualizarProducto #ID , #Nombre, #Descripcion , #Codigo , #Marca , #Precio , #Garantia , #AspectosTecnicos , #Fotografia1 , #Fotografia1 ">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Product_name" Type="String" />
<asp:Parameter Name="MRP" Type="Int32" />
<asp:Parameter Name="Our_Prize" Type="Int32" />
<asp:Parameter Name="Discount" Type="Int32" />
<asp:Parameter Name="Brand" Type="String" />
<asp:Parameter Name="Brand_image" Type="String" />
<asp:Parameter Name="Type_of_product" Type="String" />
<asp:Parameter Name="Imagepath1" Type="String" />
<asp:Parameter Name="Imagepath2" Type="String" />
<asp:Parameter Name="Imagepath3" Type="String" />
<asp:Parameter Name="Imagepath4" Type="String" />
<asp:Parameter Name="Detail" Type="String" />
<asp:Parameter Name="stock" Type="Int32" />
<asp:Parameter Name="new_arrival" Type="Int32" />
<asp:Parameter Name="best_seller" Type="Int32" />
<asp:Parameter Name="best_offer" Type="Int32" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Nombre" Type="String" />
<asp:Parameter Name="Precio" Type="Int32" />
<asp:Parameter Name="Codigo" Type="Int32" />
<asp:Parameter Name="Garantia" Type="Int32" />
<asp:Parameter Name="Marca" Type="String" />
<asp:Parameter Name="AspectosTecnicos" Type="String" />
<asp:Parameter Name="Fotografia1" Type="String" />
<asp:Parameter Name="Descripcion" Type="String" />
<asp:Parameter Name="Imagepath2" Type="String" />
<asp:Parameter Name="Imagepath3" Type="String" />
<asp:Parameter Name="Imagepath4" Type="String" />
<asp:Parameter Name="Detail" Type="String" />
<asp:Parameter Name="stock" Type="Int32" />
<asp:Parameter Name="new_arrival" Type="Int32" />
<asp:Parameter Name="best_seller" Type="Int32" />
<asp:Parameter Name="best_offer" Type="Int32" />
<asp:Parameter Name="P_ID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:Button ID="Button1" CssClass="btn btn-primary" runat="server" Text="Back To admin Console" OnClick="Button1_Click" />
</div>
</form>
</body>
So I have a gridview that is bounded with a sql data source. After that I changed a edit template for one column and instead of textBox I used a dropdownlist. In that dropdownlist I entered two items and their values. Now when I update a gridview column where I installed dropdownlist doesn't update it old value to its new value but gets a NULL value.
This is my code:
<asp:GridView ID="gvNeobrađene" HorizontalAlign="Center" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="sdsNeobradene" CellPadding="4" ForeColor="#333333" GridLines="None" OnRowUpdating="gvNeobrađene_RowUpdating">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="Ime" HeaderText="Ime" SortExpression="Ime" />
<asp:BoundField DataField="Prezime" HeaderText="Prezime" SortExpression="Prezime" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="Telefon" HeaderText="Telefon" SortExpression="Telefon" />
<asp:BoundField DataField="Napomena" HeaderText="Napomena" SortExpression="Napomena" />
<asp:BoundField DataField="SeminarID" HeaderText="SeminarID" SortExpression="SeminarID" />
<asp:BoundField DataField="TerminID" HeaderText="TerminID" SortExpression="TerminID" />
<asp:CheckBoxField DataField="PotvrdaP" HeaderText="PotvrdaP" SortExpression="PotvrdaP" ReadOnly="false"/>
<asp:TemplateField HeaderText="v" SortExpression="StatusP">
<EditItemTemplate>
<asp:DropDownList ID="ddlStatus" runat="server">
<asp:ListItem Value="Prihvaćena">Prihvaćena</asp:ListItem>
<asp:ListItem Value="Odbijena">Odbijena</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("StatusP") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Button" CancelText="Odustani" DeleteText="Izbriši" EditText="Uredi" InsertText="Ubaci" NewText="Novo" SelectText="Odaberi" ShowEditButton="True" ShowHeader="True" UpdateText="Spremi" ShowDeleteButton="True" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
<asp:SqlDataSource ID="sdsNeobradene" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:SeminarBazaConnectionString %>"
DeleteCommand="DELETE FROM [Predbiljezba] WHERE [Id] = #original_Id AND [Ime] = #original_Ime AND [Prezime] = #original_Prezime AND [Email] = #original_Email AND [Telefon] = #original_Telefon AND (([Napomena] = #original_Napomena) OR ([Napomena] IS NULL AND #original_Napomena IS NULL)) AND [SeminarID] = #original_SeminarID AND [TerminID] = #original_TerminID AND [PotvrdaP] = #original_PotvrdaP AND (([StatusP] = #original_StatusP) OR ([StatusP] IS NULL AND #original_StatusP IS NULL))" InsertCommand="INSERT INTO [Predbiljezba] ([Ime], [Prezime], [Email], [Telefon], [Napomena], [SeminarID], [TerminID], [PotvrdaP], [StatusP]) VALUES (#Ime, #Prezime, #Email, #Telefon, #Napomena, #SeminarID, #TerminID, #PotvrdaP, #StatusP)" OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT * FROM [Predbiljezba] WHERE ([PotvrdaP] = #PotvrdaP)"
UpdateCommand="UPDATE [Predbiljezba] SET [Ime] = #Ime, [Prezime] = #Prezime, [Email] = #Email, [Telefon] = #Telefon, [Napomena] = #Napomena, [SeminarID] = #SeminarID, [TerminID] = #TerminID, [PotvrdaP] = #PotvrdaP, [StatusP] = #StatusP WHERE [Id] = #original_Id">
<DeleteParameters>
<asp:Parameter Name="original_Id" Type="Int32" />
<asp:Parameter Name="original_Ime" Type="String" />
<asp:Parameter Name="original_Prezime" Type="String" />
<asp:Parameter Name="original_Email" Type="String" />
<asp:Parameter Name="original_Telefon" Type="String" />
<asp:Parameter Name="original_Napomena" Type="String" />
<asp:Parameter Name="original_SeminarID" Type="Int32" />
<asp:Parameter Name="original_TerminID" Type="Int32" />
<asp:Parameter Name="original_PotvrdaP" Type="Boolean" />
<asp:Parameter Name="original_StatusP" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Ime" Type="String" />
<asp:Parameter Name="Prezime" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="Telefon" Type="String" />
<asp:Parameter Name="Napomena" Type="String" />
<asp:Parameter Name="SeminarID" Type="Int32" />
<asp:Parameter Name="TerminID" Type="Int32" />
<asp:Parameter Name="PotvrdaP" Type="Boolean" />
<asp:Parameter Name="StatusP" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:Parameter DefaultValue="False" Name="PotvrdaP" Type="Boolean" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Ime" Type="String" />
<asp:Parameter Name="Prezime" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="Telefon" Type="String" />
<asp:Parameter Name="Napomena" Type="String" />
<asp:Parameter Name="SeminarID" Type="Int32" />
<asp:Parameter Name="TerminID" Type="Int32" />
<asp:Parameter Name="PotvrdaP" Type="Boolean" />
<asp:Parameter Name="StatusP" Type="String" />
<asp:Parameter Name="original_Id" Type="Int32" />
<asp:Parameter Name="original_Ime" Type="String" />
<asp:Parameter Name="original_Prezime" Type="String" />
<asp:Parameter Name="original_Email" Type="String" />
<asp:Parameter Name="original_Telefon" Type="String" />
<asp:Parameter Name="original_Napomena" Type="String" />
<asp:Parameter Name="original_SeminarID" Type="Int32" />
<asp:Parameter Name="original_TerminID" Type="Int32" />
<asp:Parameter Name="original_PotvrdaP" Type="Boolean" />
<asp:Parameter Name="original_StatusP" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
Is there any other stuff I need to change so this could work ?
You need to Bind your DropDownList to your database field
<asp:DropDownList ID="ddlStatus" runat="server"
SelectedValue='<%# Bind("StatusP") %>'>
<asp:ListItem Value="">None</asp:ListItem>
<asp:ListItem Value="Prihvaćena">Prihvaćena</asp:ListItem>
<asp:ListItem Value="Odbijena">Odbijena</asp:ListItem>
</asp:DropDownList>
The key part is
SelectedValue='<%# Bind("StatusP") %>'
This will cause the value you select to pass to your datasource.
I'm trying to build a very basic asp.net webpage that connects to an Azure database containing vaccine info. I have a dropdown list that initially filters on the vaccine which then pulls related data for that vaccine in a gridview.
I have also included a dropdown list that appears when I click to update the row. This second dropdown list allows me to change the vaccine type and appears in the vaccine column of the gridview.
At this point, all works. It is after I click edit, change the vaccine name from the list, and then click the update link that a few issues occur. It should be noted there is an "Active Data Set" column that uses the "bit" data type in the table being accessed/updated.
The first issue I receive is: Incorrect syntax near the keyword 'Set'.
Everything looks right in the statements, so any help here would be much appreciated.
Second issue: 'bit' is not a recognized SET option. Incorrect syntax near ','.
'bit' is not a recognized SET option. Incorrect syntax near ')'.
I believe there is an issue between the bit type in SQL and the boolean type in C#. And, while I have found discussions around this, I don't know for certain if this is the issue or how to tackle it.
Also note, while the code exists for Insert and Delete, neither is being used at this time (i.e. no buttons/links to click). It was auto-generated and I have left it in for the time being.
Explicit answers/suggestions would be appreciated as this is a new venture for me. Error message (click to enlarge) and code follows.
<%# Page Language="C#" AutoEventWireup="true" CodeFile="MasterDetails.aspx.cs" Inherits="MasterDetails" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>PAHO Price Details</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Details Page</h1>
</div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource3" DataTextField="ProductSubTypeName" DataValueField="ProductSubTypeId">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:Market_InsightsConnectionString %>" SelectCommand="SELECT [ProductSubTypeId], [ProductSubTypeName] FROM [ProductSubType]"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="PriceId" DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowEditButton="True" ShowSelectButton="True" />
<asp:BoundField DataField="PriceId" HeaderText="PriceId" InsertVisible="False" ReadOnly="True" SortExpression="PriceId" />
<asp:TemplateField HeaderText="Vaccine" SortExpression="ProductSubTypeName">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" AutoGenerateRows="False"
DataSourceID="SqlDataSource3" DataTextField="ProductSubTypeName" DataValueField="ProductSubTypeName"
SelectedValue='<%# Bind("ProductSubTypeName") %>'>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("ProductSubTypeName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CountryName" HeaderText="Country" SortExpression="CountryName" />
<asp:BoundField DataField="PriceYear" HeaderText="Year" SortExpression="PriceYear" />
<asp:BoundField DataField="Presentation" HeaderText="Presentation" SortExpression="Presentation" />
<asp:BoundField DataField="column1" HeaderText="Doses/Vial" SortExpression="Doses/Vial" />
<asp:BoundField DataField="MarketTypeName" HeaderText="Market Type" SortExpression="MarketTypeName" />
<asp:BoundField DataField="column2" HeaderText="Price/Dose (USD)" SortExpression="Price/Dose (USD)" />
<asp:BoundField DataField="Source" HeaderText="Source" SortExpression="Source" />
<asp:BoundField DataField="Comment" HeaderText="Comment" SortExpression="Comment" />
<asp:BoundField DataField="PriceSourceTypeName" HeaderText="Price Source Type" SortExpression="PriceSourceTypeName" />
<asp:CheckBoxField DataField="Active Data Set" HeaderText="Active Data Set" SortExpression="Active Data Set" />
<asp:BoundField DataField="DataSource" HeaderText="DataSource" SortExpression="DataSource" />
<asp:BoundField DataField="Date of Published Update" HeaderText="Date of Published Update" SortExpression="Date of Published Update" />
<asp:BoundField DataField="LastModifiedBy" HeaderText="LastModifiedBy" SortExpression="LastModifiedBy" />
<asp:BoundField DataField="LastModifiedDate" HeaderText="LastModifiedDate" SortExpression="LastModifiedDate" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:Market_InsightsConnectionString %>"
DeleteCommand="
DELETE FROM [Price_PAHO]
WHERE [PriceId] = #original_PriceId
AND [ProductSubTypeId] = #original_ProductSubTypeId
AND (([CountryId] = #original_CountryId) OR ([CountryId] IS NULL AND #original_CountryId IS NULL))
AND [PriceYear] = #original_PriceYear
AND (([Presentation] = #original_Presentation) OR ([Presentation] IS NULL AND #original_Presentation IS NULL))
AND (([Doses/Vial] = #original_column1) OR ([Doses/Vial] IS NULL AND #original_column1 IS NULL))
AND (([MarketTypeId] = #original_MarketTypeId) OR ([MarketTypeId] IS NULL AND #original_MarketTypeId IS NULL))
AND (([Price/Dose (USD)] = #original_column2) OR ([Price/Dose (USD)] IS NULL AND #original_column2 IS NULL))
AND (([Source] = #original_Source) OR ([Source] IS NULL AND #original_Source IS NULL))
AND (([Comment] = #original_Comment) OR ([Comment] IS NULL AND #original_Comment IS NULL))
AND [PriceSourceTypeId] = #original_PriceSourceTypeId
AND [Active Data Set] = #original_Active_Data_Set
AND [DataSource] = #original_DataSource
AND (([Date of Published Update] = #original_Date_of_Published_Update) OR ([Date of Published Update] IS NULL AND #original_Date_of_Published_Update IS NULL))
AND [LastModifiedBy] = #original_LastModifiedBy
AND [LastModifiedDate] = #original_LastModifiedDate"
InsertCommand="
INSERT INTO [Price_PAHO] (
[ProductSubTypeId]
, [CountryId]
, [PriceYear]
, [Presentation]
, [Doses/Vial]
, [MarketTypeId]
, [Price/Dose (USD)]
, [Source]
, [Comment]
, [PriceSourceTypeId]
, [Active Data Set]
, [DataSource]
, [Date of Published Update]
, [LastModifiedBy]
, [LastModifiedDate])
VALUES (
#ProductSubTypeId
, #CountryId
, #PriceYear
, #Presentation
, #column1
, #MarketTypeId
, #column2
, #Source
, #Comment
, #PriceSourceTypeId
, #Active_Data_Set
, #DataSource
, #Date_of_Published_Update
, #LastModifiedBy
, #LastModifiedDate)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="
SELECT pah.PriceId
, pst.ProductSubTypeName
, cou.CountryName
, pah.PriceYear
, pah.[Doses/Vial] AS [column1]
, mar.MarketTypeName
, pah.[Price/Dose (USD)] AS [column2]
, pah.Presentation
, pah.Source
, pah.Comment
, pri.PriceSourceTypeName
, (CASE
WHEN pah.[Active Data Set] = 1 THEN 'TRUE'
ELSE 'FALSE'
END) AS [Active Data Set]
, pah.DataSource
, pah.[Date of Published Update]
, pah.LastModifiedBy
, pah.LastModifiedDate
FROM Price_PAHO AS pah
INNER JOIN ProductSubType AS pst ON pah.ProductSubTypeId = pst.ProductSubTypeId
INNER JOIN Country AS cou ON pah.CountryId = cou.CountryId
INNER JOIN MarketType AS mar ON pah.MarketTypeId = mar.MarketTypeId
INNER JOIN PriceSourceType AS pri ON pah.PriceSourceTypeId = pri.PriceSourceTypeId
WHERE (pah.ProductSubTypeId = #ProductSubTypeId)"
UpdateCommand="
UPDATE [Price_PAHO]
SET [ProductSubTypeId] = #ProductSubTypeId
, [CountryId] = #CountryId
, [PriceYear] = #PriceYear
, [Presentation] = #Presentation
, [Doses/Vial] = #column1
, [MarketTypeId] = #MarketTypeId
, [Price/Dose (USD)] = #column2
, [Source] = #Source
, [Comment] = #Comment
, [PriceSourceTypeId] = #PriceSourceTypeId
, [Active Data Set] = #Active_Data_Set
, [DataSource] = #DataSource
, [Date of Published Update] = #Date_of_Published_Update
, [LastModifiedBy] = #LastModifiedBy
, [LastModifiedDate] = #LastModifiedDate
WHERE [PriceId] = #original_PriceId
AND [ProductSubTypeId] = #original_ProductSubTypeId
AND (([CountryId] = #original_CountryId)
OR ([CountryId] IS NULL AND #original_CountryId IS NULL))
AND [PriceYear] = #original_PriceYear
AND (([Presentation] = #original_Presentation)
OR ([Presentation] IS NULL AND #original_Presentation IS NULL))
AND (([Doses/Vial] = #original_column1)
OR ([Doses/Vial] IS NULL AND #original_column1 IS NULL))
AND (([MarketTypeId] = #original_MarketTypeId)
OR ([MarketTypeId] IS NULL AND #original_MarketTypeId IS NULL))
AND (([Price/Dose (USD)] = #original_column2)
OR ([Price/Dose (USD)] IS NULL AND #original_column2 IS NULL))
AND (([Source] = #original_Source)
OR ([Source] IS NULL AND #original_Source IS NULL))
AND (([Comment] = #original_Comment)
OR ([Comment] IS NULL AND #original_Comment IS NULL))
AND [PriceSourceTypeId] = #original_PriceSourceTypeId
AND [Active Data Set] = #original_Active_Data_Set
AND [DataSource] = #original_DataSource
AND (([Date of Published Update] = #original_Date_of_Published_Update)
OR ([Date of Published Update] IS NULL AND #original_Date_of_Published_Update IS NULL))
AND [LastModifiedBy] = #original_LastModifiedBy
AND [LastModifiedDate] = #original_LastModifiedDate">
<DeleteParameters>
<asp:Parameter Name="original_PriceId" Type="Int32" />
<asp:Parameter Name="original_ProductSubTypeId" Type="Int32" />
<asp:Parameter Name="original_CountryId" Type="Int32" />
<asp:Parameter Name="original_PriceYear" Type="Int16" />
<asp:Parameter Name="original_Presentation" Type="String" />
<asp:Parameter Name="original_column1" Type="Int16" />
<asp:Parameter Name="original_MarketTypeId" Type="Int32" />
<asp:Parameter Name="original_column2" Type="Decimal" />
<asp:Parameter Name="original_Source" Type="String" />
<asp:Parameter Name="original_Comment" Type="String" />
<asp:Parameter Name="original_PriceSourceTypeId" Type="Int16" />
<asp:Parameter Name="original_Active_Data_Set" Type="Boolean" />
<asp:Parameter Name="original_DataSource" Type="String" />
<asp:Parameter DbType="Date" Name="original_Date_of_Published_Update" />
<asp:Parameter Name="original_LastModifiedBy" Type="String" />
<asp:Parameter Name="original_LastModifiedDate" Type="DateTime" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="ProductSubTypeId" Type="Int32" />
<asp:Parameter Name="CountryId" Type="Int32" />
<asp:Parameter Name="PriceYear" Type="Int16" />
<asp:Parameter Name="Presentation" Type="String" />
<asp:Parameter Name="column1" Type="Int16" />
<asp:Parameter Name="MarketTypeId" Type="Int32" />
<asp:Parameter Name="column2" Type="Decimal" />
<asp:Parameter Name="Source" Type="String" />
<asp:Parameter Name="Comment" Type="String" />
<asp:Parameter Name="PriceSourceTypeId" Type="Int16" />
<asp:Parameter Name="Active_Data_Set" Type="Boolean" />
<asp:Parameter Name="DataSource" Type="String" />
<asp:Parameter DbType="Date" Name="Date_of_Published_Update" />
<asp:Parameter Name="LastModifiedBy" Type="String" />
<asp:Parameter Name="LastModifiedDate" Type="DateTime" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="ProductSubTypeId" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="ProductSubTypeId" Type="Int32" />
<asp:Parameter Name="CountryId" Type="Int32" />
<asp:Parameter Name="PriceYear" Type="Int16" />
<asp:Parameter Name="Presentation" Type="String" />
<asp:Parameter Name="column1" Type="Int16" />
<asp:Parameter Name="MarketTypeId" Type="Int32" />
<asp:Parameter Name="column2" Type="Decimal" />
<asp:Parameter Name="Source" Type="String" />
<asp:Parameter Name="Comment" Type="String" />
<asp:Parameter Name="PriceSourceTypeId" Type="Int16" />
<asp:Parameter Name="Active_Data_Set" Type="Boolean" />
<asp:Parameter Name="DataSource" Type="String" />
<asp:Parameter DbType="Date" Name="Date_of_Published_Update" />
<asp:Parameter Name="LastModifiedBy" Type="String" />
<asp:Parameter Name="LastModifiedDate" Type="DateTime" />
<asp:Parameter Name="original_PriceId" Type="Int32" />
<asp:Parameter Name="original_ProductSubTypeId" Type="Int32" />
<asp:Parameter Name="original_CountryId" Type="Int32" />
<asp:Parameter Name="original_PriceYear" Type="Int16" />
<asp:Parameter Name="original_Presentation" Type="String" />
<asp:Parameter Name="original_column1" Type="Int16" />
<asp:Parameter Name="original_MarketTypeId" Type="Int32" />
<asp:Parameter Name="original_column2" Type="Decimal" />
<asp:Parameter Name="original_Source" Type="String" />
<asp:Parameter Name="original_Comment" Type="String" />
<asp:Parameter Name="original_PriceSourceTypeId" Type="Int16" />
<asp:Parameter Name="original_Active_Data_Set" Type="Boolean" />
<asp:Parameter Name="original_DataSource" Type="String" />
<asp:Parameter DbType="Date" Name="original_Date_of_Published_Update" />
<asp:Parameter Name="original_LastModifiedBy" Type="String" />
<asp:Parameter Name="original_LastModifiedDate" Type="DateTime" />
</UpdateParameters>
</asp:SqlDataSource>
</form>
When editing certain column values in my gridview, other values need to change depending on that value.
For example: http://i.imgur.com/phfVtUq.png
When editing the Truck Diesel column value, the KMPerLiter and RandsPerKM values must be changed according to that value and visa versa. The formulas are as follows:
KMPerLiter = TotaKM/TruckDiesel+TrailerDiesel and RandsPerKM = Amount/TotalKM.
This must be done within the edit column of the gridview.
All these values are then stored in a table in a database.
Here is the ASP.Net html source code:
UpdateCommand="UPDATE [Loads] SET [loadDate] = #loadDate, [loadDay] = #loadDay, [loadClient] = #loadClient, [loadDriver] = #loadDriver, [loadLoadingPoint1] = #loadLoadingPoint1, [loadLoadingPoint2] = #loadLoadingPoint2, [loadLoadingPoint3] = #loadLoadingPoint3, [loadOffloadingPoint1] = #loadOffloadingPoint1, [loadOffloadingPoint2] = #loadOffloadingPoint2, [loadOffloadingPoint3] = #loadOffloadingPoint3, [loadStops] = #loadStops, [loadNumber] = #loadNumber, [loadPodNumber] = #loadPodNumber, [loadAmount] = #loadAmount, [loadTruckReg] = #loadTruckReg, [loadTrailerReg] = #loadTrailerReg, [loadCategory] = #loadCategory, [loadDayOut] = #loadDayOut, [loadNightOut] = #loadNightOut, [loadOdoStart] = #loadOdoStart, [loadOdoEnd] = #loadOdoEnd, [loadTruckDiesel] = #loadTruckDiesel, [loadTrailerDiesel] = #loadTrailerDiesel, [loadInvoiceNumber] = #loadInvoiceNumber, [loadReceiptNumber] = #loadReceiptNumber, [loadKMperLiter] = #loadKMperLiter, [loadRandsPerKM] = #loadRandsPerKM, [loadDriverWage] = #loadDriverWage, [clientRecieved] = #clientRecieved, [loadTotalKM] = #loadTotalKM, [note] = #note WHERE [loadID] = #loadID">
<UpdateParameters>
<asp:Parameter DbType="Date" Name="loadDate" />
<asp:Parameter Name="loadDay" Type="String" />
<asp:Parameter Name="loadClient" Type="String" />
<asp:Parameter Name="loadDriver" Type="String" />
<asp:Parameter Name="loadLoadingPoint1" Type="String" />
<asp:Parameter Name="loadLoadingPoint2" Type="String" />
<asp:Parameter Name="loadLoadingPoint3" Type="String" />
<asp:Parameter Name="loadOffloadingPoint1" Type="String" />
<asp:Parameter Name="loadOffloadingPoint2" Type="String" />
<asp:Parameter Name="loadOffloadingPoint3" Type="String" />
<asp:Parameter Name="loadStops" Type="Int32" />
<asp:Parameter Name="loadNumber" Type="String" />
<asp:Parameter Name="loadPodNumber" Type="String" />
<asp:Parameter Name="loadAmount" Type="Decimal" />
<asp:Parameter Name="loadTruckReg" Type="String" />
<asp:Parameter Name="loadTrailerReg" Type="String" />
<asp:Parameter Name="loadCategory" Type="String" />
<asp:Parameter Name="loadDayOut" Type="Int32" />
<asp:Parameter Name="loadNightOut" Type="Int32" />
<asp:Parameter Name="loadOdoStart" Type="Int32" />
<asp:Parameter Name="loadOdoEnd" Type="Int32" />
<asp:Parameter Name="loadTruckDiesel" Type="Decimal" />
<asp:Parameter Name="loadTrailerDiesel" Type="Decimal" />
<asp:Parameter Name="loadInvoiceNumber" Type="String" />
<asp:Parameter Name="loadReceiptNumber" Type="String" />
<asp:Parameter Name="loadKMperLiter" Type="Decimal" />
<asp:Parameter Name="loadRandsPerKM" Type="Decimal" />
<asp:Parameter Name="loadDriverWage" Type="Int32" />
<asp:Parameter Name="clientRecieved" Type="String" />
<asp:Parameter Name="loadTotalKM" Type="Int32" />
<asp:Parameter Name="note" Type="String" />
<asp:Parameter Name="loadID" Type="Int32" />
</UpdateParameters>
Thanks in advance!
Method 1:
Creating Stored Procedure
Create Proc _SPUpdateTableName
#id int,
#truckvalue numeric(18,0)
as
begin
Update TableName set KMPerLiter = TotaKM/(#truckvalue+TrailerDiesel) , TruckDiesel = #truckvalue where ID =#id
end
On SqlDataSource code :
<asp:SqlDataSource ID="LocalServerDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:SiteSqlServer %>" UpdateCommand="_SPUpdateTableName" UpdateCommandType="StoredProcedure">
<UpdateParameters>
<asp:Parameter Name="id" Type="Int32" />
<asp:Parameter Name="truckvalue " Type="Decimal" />
</UpdateParameters>
</asp:SqlDataSource>
Or Else in RowUpdate Method you can calculate the parameters and assign them to your UpdateCommand statement Parameter :
Method 2:
protected void grdvechile_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
decimal truckvalue= Convert.ToDecimal( grdvechile.Rows[e.RowIndex].Cells[1].Text);
// fetch all value as needed and typecast
decimal KMPerLiter = TotaKM/(truckvalue+TrailerDiesel);
//Pass your required parameter
LocalServerDataSource.UpdateParameters["truckvalue"].DefaultValue = truckvalue;
LocalServerDataSource.UpdateParameters["KMPerLiter "].DefaultValue = KMPerLiter ;
LocalServerDataSource.Update();
}
catch { }
}
Note: These code is only on logic I thought will be appicable for your situation not tested.Change as per your Requirment.
No need.. Only create a virtual table to pick up the Grid view value, Then change it according to your requirement, again reassign it to Grid view
i have a webform with a gridview. i have the UPDATE button next to each row. however when i press the button and edit the field and press UPDATE. it does not change anything. here's the code:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="lom_number" DataSourceID="SqlDataSource1" ForeColor="#333333"
GridLines="None" onselectedindexchanged="GridView1_SelectedIndexChanged">
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
ShowSelectButton="True" />
<asp:BoundField DataField="occurrence_date" HeaderText="occurrence_date"
SortExpression="occurrence_date" />
<asp:BoundField DataField="report_date" HeaderText="report_date"
SortExpression="report_date" />
<asp:BoundField DataField="report_by" HeaderText="report_by"
SortExpression="report_by" />
<asp:BoundField DataField="identified_by" HeaderText="identified_by"
SortExpression="identified_by" />
<asp:BoundField DataField="section_c_issue_error_identified_by"
HeaderText="section_c_issue_error_identified_by"
SortExpression="section_c_issue_error_identified_by" />
<asp:BoundField DataField="section_c_comments" HeaderText="section_c_comments"
SortExpression="section_c_comments" />
<asp:BoundField DataField="section_d_investigation"
HeaderText="section_d_investigation" SortExpression="section_d_investigation" />
<asp:BoundField DataField="section_e_corrective_action"
HeaderText="section_e_corrective_action"
SortExpression="section_e_corrective_action" />
<asp:BoundField DataField="section_f_comments" HeaderText="section_f_comments"
SortExpression="section_f_comments" />
<asp:BoundField DataField="pre_practice_code" HeaderText="pre_practice_code"
SortExpression="pre_practice_code" />
<asp:BoundField DataField="pre_contact" HeaderText="pre_contact"
SortExpression="pre_contact" />
<asp:BoundField DataField="lom_number" HeaderText="lom_number"
InsertVisible="False" ReadOnly="True" SortExpression="lom_number" />
<asp:BoundField DataField="windows_user" HeaderText="windows_user"
SortExpression="windows_user" />
<asp:BoundField DataField="computer_name" HeaderText="computer_name"
SortExpression="computer_name" />
<asp:BoundField DataField="time_stamp" HeaderText="time_stamp"
SortExpression="time_stamp" />
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:LOM %>"
SelectCommand="SELECT * FROM [Main_LOM_Form]"
ConflictDetection="CompareAllValues"
DeleteCommand="DELETE FROM [Main_LOM_Form] WHERE [lom_number] = #original_lom_number AND (([occurrence_date] = #original_occurrence_date) OR ([occurrence_date] IS NULL AND #original_occurrence_date IS NULL)) AND (([report_date] = #original_report_date) OR ([report_date] IS NULL AND #original_report_date IS NULL)) AND (([report_by] = #original_report_by) OR ([report_by] IS NULL AND #original_report_by IS NULL)) AND (([identified_by] = #original_identified_by) OR ([identified_by] IS NULL AND #original_identified_by IS NULL)) AND (([section_c_issue_error_identified_by] = #original_section_c_issue_error_identified_by) OR ([section_c_issue_error_identified_by] IS NULL AND #original_section_c_issue_error_identified_by IS NULL)) AND (([section_c_comments] = #original_section_c_comments) OR ([section_c_comments] IS NULL AND #original_section_c_comments IS NULL)) AND (([section_d_investigation] = #original_section_d_investigation) OR ([section_d_investigation] IS NULL AND #original_section_d_investigation IS NULL)) AND (([section_e_corrective_action] = #original_section_e_corrective_action) OR ([section_e_corrective_action] IS NULL AND #original_section_e_corrective_action IS NULL)) AND (([section_f_comments] = #original_section_f_comments) OR ([section_f_comments] IS NULL AND #original_section_f_comments IS NULL)) AND (([pre_practice_code] = #original_pre_practice_code) OR ([pre_practice_code] IS NULL AND #original_pre_practice_code IS NULL)) AND (([pre_contact] = #original_pre_contact) OR ([pre_contact] IS NULL AND #original_pre_contact IS NULL)) AND [windows_user] = #original_windows_user AND [computer_name] = #original_computer_name AND [time_stamp] = #original_time_stamp"
InsertCommand="INSERT INTO [Main_LOM_Form] ([occurrence_date], [report_date], [report_by], [identified_by], [section_c_issue_error_identified_by], [section_c_comments], [section_d_investigation], [section_e_corrective_action], [section_f_comments], [pre_practice_code], [pre_contact], [windows_user], [computer_name], [time_stamp]) VALUES (#occurrence_date, #report_date, #report_by, #identified_by, #section_c_issue_error_identified_by, #section_c_comments, #section_d_investigation, #section_e_corrective_action, #section_f_comments, #pre_practice_code, #pre_contact, #windows_user, #computer_name, #time_stamp)"
OldValuesParameterFormatString="original_{0}"
UpdateCommand="UPDATE [Main_LOM_Form] SET [occurrence_date] = #occurrence_date, [report_date] = #report_date, [report_by] = #report_by, [identified_by] = #identified_by, [section_c_issue_error_identified_by] = #section_c_issue_error_identified_by, [section_c_comments] = #section_c_comments, [section_d_investigation] = #section_d_investigation, [section_e_corrective_action] = #section_e_corrective_action, [section_f_comments] = #section_f_comments, [pre_practice_code] = #pre_practice_code, [pre_contact] = #pre_contact, [windows_user] = #windows_user, [computer_name] = #computer_name, [time_stamp] = #time_stamp WHERE [lom_number] = #original_lom_number AND (([occurrence_date] = #original_occurrence_date) OR ([occurrence_date] IS NULL AND #original_occurrence_date IS NULL)) AND (([report_date] = #original_report_date) OR ([report_date] IS NULL AND #original_report_date IS NULL)) AND (([report_by] = #original_report_by) OR ([report_by] IS NULL AND #original_report_by IS NULL)) AND (([identified_by] = #original_identified_by) OR ([identified_by] IS NULL AND #original_identified_by IS NULL)) AND (([section_c_issue_error_identified_by] = #original_section_c_issue_error_identified_by) OR ([section_c_issue_error_identified_by] IS NULL AND #original_section_c_issue_error_identified_by IS NULL)) AND (([section_c_comments] = #original_section_c_comments) OR ([section_c_comments] IS NULL AND #original_section_c_comments IS NULL)) AND (([section_d_investigation] = #original_section_d_investigation) OR ([section_d_investigation] IS NULL AND #original_section_d_investigation IS NULL)) AND (([section_e_corrective_action] = #original_section_e_corrective_action) OR ([section_e_corrective_action] IS NULL AND #original_section_e_corrective_action IS NULL)) AND (([section_f_comments] = #original_section_f_comments) OR ([section_f_comments] IS NULL AND #original_section_f_comments IS NULL)) AND (([pre_practice_code] = #original_pre_practice_code) OR ([pre_practice_code] IS NULL AND #original_pre_practice_code IS NULL)) AND (([pre_contact] = #original_pre_contact) OR ([pre_contact] IS NULL AND #original_pre_contact IS NULL)) AND [windows_user] = #original_windows_user AND [computer_name] = #original_computer_name AND [time_stamp] = #original_time_stamp">
<DeleteParameters>
<asp:Parameter Name="original_lom_number" Type="Int32" />
<asp:Parameter DbType="Date" Name="original_occurrence_date" />
<asp:Parameter DbType="Date" Name="original_report_date" />
<asp:Parameter Name="original_report_by" Type="String" />
<asp:Parameter Name="original_identified_by" Type="String" />
<asp:Parameter Name="original_section_c_issue_error_identified_by"
Type="String" />
<asp:Parameter Name="original_section_c_comments" Type="String" />
<asp:Parameter Name="original_section_d_investigation" Type="String" />
<asp:Parameter Name="original_section_e_corrective_action" Type="String" />
<asp:Parameter Name="original_section_f_comments" Type="String" />
<asp:Parameter Name="original_pre_practice_code" Type="String" />
<asp:Parameter Name="original_pre_contact" Type="String" />
<asp:Parameter Name="original_windows_user" Type="String" />
<asp:Parameter Name="original_computer_name" Type="String" />
<asp:Parameter Name="original_time_stamp" Type="DateTime" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter DbType="Date" Name="occurrence_date" />
<asp:Parameter DbType="Date" Name="report_date" />
<asp:Parameter Name="report_by" Type="String" />
<asp:Parameter Name="identified_by" Type="String" />
<asp:Parameter Name="section_c_issue_error_identified_by" Type="String" />
<asp:Parameter Name="section_c_comments" Type="String" />
<asp:Parameter Name="section_d_investigation" Type="String" />
<asp:Parameter Name="section_e_corrective_action" Type="String" />
<asp:Parameter Name="section_f_comments" Type="String" />
<asp:Parameter Name="pre_practice_code" Type="String" />
<asp:Parameter Name="pre_contact" Type="String" />
<asp:Parameter Name="windows_user" Type="String" />
<asp:Parameter Name="computer_name" Type="String" />
<asp:Parameter Name="time_stamp" Type="DateTime" />
<asp:Parameter Name="original_lom_number" Type="Int32" />
<asp:Parameter DbType="Date" Name="original_occurrence_date" />
<asp:Parameter DbType="Date" Name="original_report_date" />
<asp:Parameter Name="original_report_by" Type="String" />
<asp:Parameter Name="original_identified_by" Type="String" />
<asp:Parameter Name="original_section_c_issue_error_identified_by"
Type="String" />
<asp:Parameter Name="original_section_c_comments" Type="String" />
<asp:Parameter Name="original_section_d_investigation" Type="String" />
<asp:Parameter Name="original_section_e_corrective_action" Type="String" />
<asp:Parameter Name="original_section_f_comments" Type="String" />
<asp:Parameter Name="original_pre_practice_code" Type="String" />
<asp:Parameter Name="original_pre_contact" Type="String" />
<asp:Parameter Name="original_windows_user" Type="String" />
<asp:Parameter Name="original_computer_name" Type="String" />
<asp:Parameter Name="original_time_stamp" Type="DateTime" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter DbType="Date" Name="occurrence_date" />
<asp:Parameter DbType="Date" Name="report_date" />
<asp:Parameter Name="report_by" Type="String" />
<asp:Parameter Name="identified_by" Type="String" />
<asp:Parameter Name="section_c_issue_error_identified_by" Type="String" />
<asp:Parameter Name="section_c_comments" Type="String" />
<asp:Parameter Name="section_d_investigation" Type="String" />
<asp:Parameter Name="section_e_corrective_action" Type="String" />
<asp:Parameter Name="section_f_comments" Type="String" />
<asp:Parameter Name="pre_practice_code" Type="String" />
<asp:Parameter Name="pre_contact" Type="String" />
<asp:Parameter Name="windows_user" Type="String" />
<asp:Parameter Name="computer_name" Type="String" />
<asp:Parameter Name="time_stamp" Type="DateTime" />
</InsertParameters>
</asp:SqlDataSource>
here is the query that it i intercepted with james' help:
updateQuery "UPDATE [Main_LOM_Form] SET [occurrence_date] = #occurrence_date, [report_date] = #report_date, [report_by] = #report_by, [identified_by] = #identified_by, [section_c_issue_error_identified_by] = #section_c_issue_error_identified_by, [section_c_comments] = #section_c_comments, [section_d_investigation] = #section_d_investigation, [section_e_corrective_action] = #section_e_corrective_action, [section_f_comments] = #section_f_comments, [pre_practice_code] = #pre_practice_code, [pre_contact] = #pre_contact, [windows_user] = #windows_user, [computer_name] = #computer_name, [time_stamp] = #time_stamp WHERE [lom_number] = #original_lom_number AND (([occurrence_date] = #original_occurrence_date) OR ([occurrence_date] IS NULL AND #original_occurrence_date IS NULL)) AND (([report_date] = #original_report_date) OR ([report_date] IS NULL AND #original_report_date IS NULL)) AND (([report_by] = #original_report_by) OR ([report_by] IS NULL AND #original_report_by IS NULL)) AND (([identified_by] = #original_identified_by) OR ([identified_by] IS NULL AND #original_identified_by IS NULL)) AND (([section_c_issue_error_identified_by] = #original_section_c_issue_error_identified_by) OR ([section_c_issue_error_identified_by] IS NULL AND #original_section_c_issue_error_identified_by IS NULL)) AND (([section_c_comments] = #original_section_c_comments) OR ([section_c_comments] IS NULL AND #original_section_c_comments IS NULL)) AND (([section_d_investigation] = #original_section_d_investigation) OR ([section_d_investigation] IS NULL AND #original_section_d_investigation IS NULL)) AND (([section_e_corrective_action] = #original_section_e_corrective_action) OR ([section_e_corrective_action] IS NULL AND #original_section_e_corrective_action IS NULL)) AND (([section_f_comments] = #original_section_f_comments) OR ([section_f_comments] IS NULL AND #original_section_f_comments IS NULL)) AND (([pre_practice_code] = #original_pre_practice_code) OR ([pre_practice_code] IS NULL AND #original_pre_practice_code IS NULL)) AND (([pre_contact] = #original_pre_contact) OR ([pre_contact] IS NULL AND #original_pre_contact IS NULL)) AND [windows_user] = #original_windows_user AND [computer_name] = #original_computer_name AND [time_stamp] = #original_time_stamp" string
what am i doing wrong?
I would suggest adding an OnUpdating event handler so you can look at the CommandText before the query is executed. That should help you identify if there's an issue with the query.
In the markup:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" OnUpdating="SqlDataSource1_Updating" ... >
In the code-behind:
protected void SqlDataSource1_Updating(object sender, SqlDataSourceCommandEventArgs e)
{
string updateQuery = e.Command.CommandText;
//inspect the update query
}