<asp:View ID="View2" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" CellSpacing="2" DataKeyNames="Kimlik" DataSourceID="SqlDataSource1" ForeColor="Black">
<Columns>
<asp:BoundField DataField="Kimlik" HeaderText="Kimlik" InsertVisible="False" ReadOnly="True" SortExpression="Kimlik" />
<asp:BoundField DataField="uye_ad" HeaderText="uye_ad" SortExpression="uye_ad" />
<asp:BoundField DataField="uye_soyad" HeaderText="uye_soyad" SortExpression="uye_soyad" />
<asp:BoundField DataField="kadi" HeaderText="kadi" SortExpression="kadi" />
<asp:BoundField DataField="sifre" HeaderText="sifre" SortExpression="sifre" />
<asp:BoundField DataField="mail" HeaderText="mail" SortExpression="mail" />
<asp:BoundField DataField="tc" HeaderText="tc" SortExpression="tc" />
<asp:CommandField ShowEditButton="True" />
</Columns>
<EditRowStyle HorizontalAlign="Left" />
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
<RowStyle BackColor="White" Width="200px" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" CssClass="<br/>" />
<SortedAscendingHeaderStyle BackColor="#808080" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" DeleteCommand="DELETE FROM [uyeler] WHERE [Kimlik] = ?" InsertCommand="INSERT INTO [uyeler] ([Kimlik], [uye_ad], [uye_soyad], [kadi], [sifre], [mail], [tc]) VALUES (?, ?, ?, ?, ?, ?, ?)" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [uyeler] WHERE ([mail] = ?)" UpdateCommand="UPDATE [uyeler] SET [uye_ad] = ?, [uye_soyad] = ?, [kadi] = ?, [sifre] = ?, [mail] = ?, [tc] = ? WHERE [Kimlik] = ?">
<DeleteParameters>
<asp:Parameter Name="Kimlik" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Kimlik" Type="Int32" />
<asp:Parameter Name="uye_ad" Type="String" />
<asp:Parameter Name="uye_soyad" Type="String" />
<asp:Parameter Name="kadi" Type="String" />
<asp:Parameter Name="sifre" Type="String" />
<asp:Parameter Name="mail" Type="String" />
<asp:Parameter Name="tc" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:SessionParameter Name="mail" SessionField="mail" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="uye_ad" Type="String" />
<asp:Parameter Name="uye_soyad" Type="String" />
<asp:Parameter Name="kadi" Type="String" />
<asp:Parameter Name="sifre" Type="String" />
<asp:Parameter Name="mail" Type="String" />
<asp:Parameter Name="tc" Type="String" />
<asp:Parameter Name="Kimlik" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
</asp:View>
I'm developing a project with asp.net c #. I used the GridView object in my web pages. but update, delete, insert operations in the 'must-user operation on Updateable query' I get an error. I used the access the database. I gave all the powers of puberty folder database. but the problem still continues. try, catch, finally I used the tags error still continues. please help me.!
Here's the
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
DeleteCommand="DELETE FROM [uyeler]
WHERE [Kimlik] = ?"
InsertCommand="INSERT INTO [uyeler]
([Kimlik], [uye_ad], [uye_soyad], [kadi], [sifre], [mail], [tc])
VALUES (?, ?, ?, ?, ?, ?, ?)"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="
SELECT * FROM [uyeler]
WHERE ([mail] = ?)"
UpdateCommand="
UPDATE [uyeler]
SET [uye_ad] = ?, [uye_soyad] = ?, [kadi] = ?, [sifre] = ?, [mail] = ?, [tc] = ?
WHERE [Kimlik] = ?
">
Related
AccessDataSource doesnt pick up edited data from GridView and it doesnt save it to database.
Can someone tell what am I doing wrong here? Updating the database doesnt work.
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/baza.mdb"
SelectCommand="SELECT * FROM [users]"
DeleteCommand="DELETE FROM users WHERE (username = ?)"
InsertCommand="INSERT INTO users(username, [password], isAdmin) VALUES (?, ?, ?)"
OldValuesParameterFormatString="original_{0}"
UpdateCommand="UPDATE [users] SET [username] = ?, [password] = ?, [isAdmin] = ? WHERE ([username] = ?)">
<DeleteParameters>
<asp:Parameter DbType="String" Name="username" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter DbType="String" Name="username" />
<asp:Parameter DbType="String" Name="password" />
<asp:Parameter DbType="String" Name="isAdmin" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter DbType="String" Name="username" />
<asp:Parameter DbType="String" Name="password" />
<asp:Parameter DbType="String" Name="isAdmin" />
<asp:Parameter DbType="String" Name="original_username" />
</UpdateParameters>
</asp:AccessDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="username" DataSourceID="AccessDataSource1" AllowPaging="True" CellPadding="10" ForeColor="#333333" GridLines="None" AllowSorting="True" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True">
<AlternatingRowStyle BackColor="White" ForeColor="#284775"></AlternatingRowStyle>
<Columns>
<asp:BoundField DataField="username" HeaderText="username" SortExpression="username" ItemStyle-HorizontalAlign="Center"></asp:BoundField>
<asp:BoundField DataField="password" HeaderText="password" SortExpression="password"></asp:BoundField>
<asp:BoundField DataField="isAdmin" HeaderText="isAdmin" SortExpression="isAdmin"></asp:BoundField>
</Columns>
<EditRowStyle BackColor="#999999"></EditRowStyle>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"></FooterStyle>
<HeaderStyle Font-Bold="True" ForeColor="#cecece"></HeaderStyle>
<PagerStyle HorizontalAlign="Center" BackColor="#284775" ForeColor="#284775"></PagerStyle>
<RowStyle BackColor="#f8f8f9" ForeColor="#fff"></RowStyle>
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333"></SelectedRowStyle>
</asp:GridView>
I cannot get the GridView to bind to DataRowView with the datasource below, however it does work if I use the wildcard.?
THIS FAILS:
ERROR: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'EnrollmentsTbl.AutoNum'
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" DataKeyNames="EnrollmentsTbl.AutoNum"
DataSourceID="AccessDataSource1" ForeColor="Black" GridLines="Vertical" PageSize="100">
<PagerSettings Mode="NumericFirstLast" PageButtonCount="75" />
<FooterStyle BackColor="#CCCCCC" />
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="EnrollmentsTbl.AutoNum" HeaderText="AutoNum" InsertVisible="False" ReadOnly="True" SortExpression="EnrollmentsTbl.AutoNum" />
<asp:BoundField DataField="SubmitTime" HeaderText="SubmitTime" SortExpression="SubmitTime" />
<asp:BoundField DataField="ClassName" HeaderText="ClassName" SortExpression="ClassName" />
<asp:BoundField DataField="ClassDate" HeaderText="ClassDate" SortExpression="ClassDate" DataFormatString="{0:MM/dd/yyyy}" HtmlEncode="False"/>
<asp:BoundField DataField="DateCompleted" HeaderText="DateCompleted" SortExpression="DateCompleted" DataFormatString="{0:MM/dd/yyyy}" HtmlEncode="False"/>
<asp:CheckBoxField DataField="Completed" HeaderText="Completed" SortExpression="Completed" />
<asp:BoundField DataField="EnrollmentsTbl.UID" HeaderText="UID" ReadOnly="True" SortExpression="EnrollmentsTbl.UID" />
</Columns>
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#6699CC" />
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="<%$ ConnectionStrings:AccessSubSiteString %>"
DeleteCommand="DELETE FROM [EnrollmentsTbl] WHERE [EnrollmentsTbl.AutoNum] = ?"
SelectCommand="SELECT EnrollmentsTbl.AutoNum, EnrollmentsTbl.SubmitTime, EnrollmentsTbl.ClassName,
EnrollmentsTbl.ClassDate, EnrollmentsTbl.DateCompleted, EnrollmentsTbl.Completed, EnrollmentsTbl.UID
FROM [EnrollmentsTbl] INNER JOIN [UsersDataTbl] ON EnrollmentsTbl.UID = UsersDataTbl.UID
WHERE ([EnrollmentsTbl.AutoNum] > ?)"
UpdateCommand="UPDATE [EnrollmentsTbl] SET [UserName] = ?, [SubmitTime] = ?, [ClassName] = ?, [ClassDate] = ?,
[ClassTime] = ?, [Enrolled] = ?, [WaitListed] = ?, [Instructor] = ?, [DateCompleted] = ?, [Completed] = ?, [Walkin] = ?
WHERE [EnrollmentsTbl.AutoNum] = ?">
<SelectParameters>
<asp:ControlParameter ControlID="UserNameTB" DefaultValue="" Name="?" PropertyName="Text" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="EnrollmentsTbl.AutoNum" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="UserName" Type="String" />
<asp:Parameter Name="SubmitTime" Type="DateTime" />
<asp:Parameter Name="ClassName" Type="String" />
<asp:Parameter Name="ClassDate" Type="DateTime" />
<asp:Parameter Name="ClassTime" Type="String" />
<asp:Parameter Name="Enrolled" Type="Boolean" />
<asp:Parameter Name="WaitListed" Type="Boolean" />
<asp:Parameter Name="Instructor" Type="String" />
<asp:Parameter Name="DateCompleted" Type="DateTime" />
<asp:Parameter Name="Completed" Type="Boolean" />
<asp:Parameter Name="Walkin" Type="Boolean" />
<asp:Parameter Name="EnrollmentsTbl.AutoNum" Type="Int32" />
</UpdateParameters>
</asp:AccessDataSource>
However:
changing the SELECTCOMMAND="SELECT * FROM... allows it to work?
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="<%$ ConnectionStrings:AccessSubSiteString %>"
DeleteCommand="DELETE FROM [EnrollmentsTbl] WHERE [EnrollmentsTbl.AutoNum] = ?"
SelectCommand="SELECT *
FROM [EnrollmentsTbl] INNER JOIN [UsersDataTbl] ON EnrollmentsTbl.UID = UsersDataTbl.UID
WHERE ([EnrollmentsTbl.AutoNum] > ?)"
UpdateCommand="UPDATE [EnrollmentsTbl] SET [UserName] = ?, [SubmitTime] = ?, [ClassName] = ?, [ClassDate] = ?,
[ClassTime] = ?, [Enrolled] = ?, [WaitListed] = ?, [Instructor] = ?, [DateCompleted] = ?, [Completed] = ?, [Walkin] = ?
WHERE [EnrollmentsTbl.AutoNum] = ?">
<SelectParameters>
<asp:ControlParameter ControlID="UserNameTB" DefaultValue="" Name="?" PropertyName="Text" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="EnrollmentsTbl.AutoNum" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="UserName" Type="String" />
<asp:Parameter Name="SubmitTime" Type="DateTime" />
<asp:Parameter Name="ClassName" Type="String" />
<asp:Parameter Name="ClassDate" Type="DateTime" />
<asp:Parameter Name="ClassTime" Type="String" />
<asp:Parameter Name="Enrolled" Type="Boolean" />
<asp:Parameter Name="WaitListed" Type="Boolean" />
<asp:Parameter Name="Instructor" Type="String" />
<asp:Parameter Name="DateCompleted" Type="DateTime" />
<asp:Parameter Name="Completed" Type="Boolean" />
<asp:Parameter Name="Walkin" Type="Boolean" />
<asp:Parameter Name="EnrollmentsTbl.AutoNum" Type="Int32" />
</UpdateParameters>
</asp:AccessDataSource>
I need fields from bith tabes in the gridview so the wildcard is not going to work.
No help offered, but it appears I found a resolution/work-a-round:
Part of the problem was that when the wildcard (*) is used in the SELECT statement (SelectCommand) the fields returned from an INNER JOIN are mixed, some have table.column and others just column. example: if both tables contain AutoNum then table1.AutoNum and table2.AutNum are both returned - but if only one table has a field it is returned as only Field - this was the problem with setting the column names in the gridview that was causing my problem.
I've worked on this for a while and realized that my DetailsView actually works fine by itself (I tested it on another page).
But when I put it in the tab layout of the page, and click Edit, it clears all values in the database with null values on updating.
For example here's the page: http://pactlegacy.com/sentinel/employeeprofile.aspx?curEmp=3
Here's the DetailsView:
<div id="tab-general" class="tabs-content">
<div class="avatar">
<h3>General Information</h3>
</div>
<fieldset class="grey-bg">
<legend>Required fields</legend>
<div class="colx3-left-double">
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px"
AutoGenerateRows="False" DataKeyNames="ID" DataSourceID="SqlDataSource1">
<Fields>
<asp:CommandField ShowEditButton="True" ButtonType="Button"/>
<asp:BoundField DataField="FirstName" HeaderText="First Name"
SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="Last Name"
SortExpression="LastName" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="JobID" HeaderText="JobID" SortExpression="JobID" />
<asp:BoundField DataField="SupervisorID" HeaderText="SupervisorID"
SortExpression="SupervisorID" />
<asp:BoundField DataField="HireDate" HeaderText="Hire Date"
SortExpression="HireDate" />
<asp:BoundField DataField="Status" HeaderText="Status"
SortExpression="Status" />
<asp:CommandField ShowEditButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:dbConnectionString %>"
DeleteCommand="DELETE FROM [Users] WHERE [ID] = #ID"
InsertCommand="INSERT INTO [Users] ([ClientID], [UserName], [Password], [FirstName], [LastName], [Email], [JobID], [SupervisorID], [HireDate], [Status]) VALUES (#ClientID, #UserName, #Password, #FirstName, #LastName, #Email, #JobID, #SupervisorID, #HireDate, #Status)"
ProviderName="<%$ ConnectionStrings:dbConnectionString.ProviderName %>"
SelectCommand="SELECT [ID], [ClientID], [UserName], [Password], [FirstName], [LastName], [Email], [JobID], [SupervisorID], [HireDate], [Status] FROM [Users] WHERE [ID] = #ID"
UpdateCommand="UPDATE [Users] SET [ClientID] = #ClientID, [UserName] = #UserName, [Password] = #Password, [FirstName] = #FirstName, [LastName] = #LastName, [Email] = #Email, [JobID] = #JobID, [SupervisorID] = #SupervisorID, [HireDate] = #HireDate, [Status] = #Status WHERE [ID] = #ID">
<SelectParameters>
<asp:QueryStringParameter Name="ID" QueryStringField="curEmp" Type="Int64" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="ClientID" Type="Int64" />
<asp:Parameter Name="UserName" Type="String" />
<asp:Parameter Name="Password" Type="String" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="JobID" Type="Double" />
<asp:Parameter Name="SupervisorID" Type="Double" />
<asp:Parameter Name="HireDate" Type="DateTime" />
<asp:Parameter Name="Status" Type="String" />
<asp:Parameter Name="ID" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
</fieldset>
</div>
Does anyone know why this is happening? What do I need to change have my DetailsView update properly within my tab layout?
You need to add an ID field in the DetailsView like below:
<asp:BoundField
DataField="ID"
HeaderText="ID"
InsertVisible="False"
ReadOnly="True"
SortExpression="ID" />
This is the primary key you are missing in DetailsView.
Please forgive my ignorance. I have a done a bit of web programming but am new to ASP.NET and find it mystifying when trying to do something not out of the box.
I have a GridView that gets its data from a SQL Server view. I have a DetailsView that needs to manipulate data in a table. I cannot figure out how to link the GridView to the DetailsView correctly.
Below is the code for the section of the aspx page that contains the GridView and DetailsView. The latest error in an endless procession of errors is: Must declare the scalar variable "#ID".
I would appreciate any help that anyone can offer. Thanks.
<asp:GridView ID="gvVendorContacts" runat="server" AutoGenerateColumns="False"
DataSourceID="dsApplications_Contacts" AllowSorting="True" CellPadding="4" CellSpacing="2" AutoGenerateSelectButton="True" DataKeyNames="ContactID"
onselectedindexchanged="gvVendorContacts_SelectedIndexChanged">
<AlternatingRowStyle BackColor="#E8F3FF" />
<Columns>
<asp:BoundField DataField="FullName" HeaderText="Name" ReadOnly="True"
SortExpression="FullName" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="Role" HeaderText="Role" SortExpression="Role" />
<asp:BoundField DataField="Office Phone" HeaderText="Office Phone"
SortExpression="Office Phone" />
<asp:BoundField DataField="Mobile Phone" HeaderText="Mobile Phone"
SortExpression="Mobile Phone" />
<asp:TemplateField HeaderText="Email" SortExpression="Email">
<ItemTemplate>
<%#Eval("Email")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="dsApplications_Contacts" runat="server"
ConnectionString="<%$ ConnectionStrings:MDSConnectionString %>"
SelectCommand="SELECT [ApplicationID], [ContactID], [FName], [LName], [FullName], [Title], [Role], [OfficePhone] As [Office Phone], [MobilePhone] As [Mobile Phone], [Email] FROM [vw_Applications_Contacts] WHERE ApplicationName = 'Bloomberg'">
</asp:SqlDataSource>
<asp:DetailsView ID="dvVendorContacts" runat="server" AutoGenerateRows="False"
DataKeyNames="ID" DataSourceID="dsVendorContacts" Height="100px"
Width="200px" BackColor="White" BorderColor="#CC9966" BorderStyle="None"
BorderWidth="1px" CellPadding="4">
<EditRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<Fields>
<asp:BoundField DataField="ContactID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="FName" HeaderText="FName" SortExpression="FName" />
<asp:BoundField DataField="LName" HeaderText="LName" SortExpression="LName" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="Role" HeaderText="Role" SortExpression="Role" />
<asp:BoundField DataField="OfficePhone" HeaderText="OfficePhone"
SortExpression="OfficePhone" />
<asp:BoundField DataField="MobilePhone" HeaderText="MobilePhone"
SortExpression="MobilePhone" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
</Fields>
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<RowStyle BackColor="White" ForeColor="#330099" />
</asp:DetailsView>
<asp:SqlDataSource ID="dsVendorContacts" runat="server"
ConnectionString="<%$ ConnectionStrings:MDSConnectionString %>"
DeleteCommand="DELETE FROM [Contacts] WHERE [ID] = #ID"
InsertCommand="INSERT INTO [Contacts] ([FName], [LName], [Title], [Role], [OfficePhone], [MobilePhone], [Email]) VALUES (#FName, #LName, #Title, #Role, #OfficePhone, #MobilePhone, #Email)"
SelectCommand="SELECT [ID], [FName], [LName], [Title], [Role], [OfficePhone], [MobilePhone], [Email] FROM [Contacts] WHERE ([ID] = #ID)"
UpdateCommand="UPDATE [Contacts] SET [FName] = #FName, [LName] = #LName, [Title] = #Title, [Role] = #Role, [OfficePhone] = #OfficePhone, [MobilePhone] = #MobilePhone, [Email] = #Email WHERE [ID] = #ID">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="FName" Type="String" />
<asp:Parameter Name="LName" Type="String" />
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Role" Type="String" />
<asp:Parameter Name="OfficePhone" Type="String" />
<asp:Parameter Name="MobilePhone" Type="String" />
<asp:Parameter Name="Email" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="FName" Type="String" />
<asp:Parameter Name="LName" Type="String" />
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Role" Type="String" />
<asp:Parameter Name="OfficePhone" Type="String" />
<asp:Parameter Name="MobilePhone" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="gvVendorContacts" DefaultValue="NULL"
Name="ContactID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
Looks like your select statement is expecting #ID but your SelectParameter is ContactId.
I'm having this problem where once I've calculated to display (Quantity * Price) As Total FROM ShoppingCart, it managed to display the total for the total item user purchased but I couldn't update or delete at the column and when I update it straight away give me this error "Incorrect syntax near the keyword 'WHERE'"
I'll Provide the code here:
<asp:GridView ID="GridView2" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CellPadding="4"
DataSourceID="SqlDataSource2" ForeColor="#333333" GridLines="None"
AllowSorting="True">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="ProductID" HeaderText="ProductID"
SortExpression="ProductID" />
<asp:BoundField DataField="UserName" HeaderText="UserName"
SortExpression="UserName" />
<asp:BoundField DataField="InsertDate" HeaderText="InsertDate"
SortExpression="InsertDate" />
<asp:BoundField DataField="Quantity" HeaderText="Quantity"
SortExpression="Quantity" />
<asp:BoundField DataField="Price" HeaderText="Price"
SortExpression="Price" />
<asp:BoundField DataField="OrderID" HeaderText="OrderID"
SortExpression="OrderID" />
<asp:BoundField DataField="Total" HeaderText="Total"
SortExpression="Total" />
</Columns>
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
DeleteCommand="DELETE FROM [ShoppingCart] WHERE [CartID] = #original_CartID AND [ProductID] = #original_ProductID AND [UserName] = #original_UserName AND [InsertDate] = #original_InsertDate AND [Quantity] = #original_Quantity AND [Price] = #original_Price AND [OrderID] = #original_OrderID AND [Total]= #original_Total"
InsertCommand="INSERT INTO [ShoppingCart] ([ProductID], [UserName], [InsertDate], [Quantity], [Price], [OrderID], [Total]) VALUES (#ProductID, #UserName, #InsertDate, #Quantity, #Price, #OrderID, #Total)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT [ProductID], [UserName], [InsertDate], [Quantity], [Price], [OrderID], (Quantity * Price) As Total FROM [ShoppingCart]"
UpdateCommand="UPDATE [ShoppingCart] SET [ProductID] = #ProductID, [UserName] = #UserName, [InsertDate] = #InsertDate, [Quantity] = #Quantity, [Price] = #Price, [OrderID] = #OrderID, [Total]= #Total, WHERE [CartID] = #original_CartID AND [ProductID] = #original_ProductID AND [UserName] = #original_UserName AND [InsertDate] = #original_InsertDate AND [Quantity] = #original_Quantity AND [Price] = #original_Price AND [OrderID] = #original_OrderID AND [Total]= #Total">
<DeleteParameters>
<asp:Parameter Name="original_CartID" Type="Int32" />
<asp:Parameter Name="original_ProductID" Type="Int32" />
<asp:Parameter Name="original_UserName" Type="String" />
<asp:Parameter Name="original_InsertDate" Type="DateTime" />
<asp:Parameter Name="original_Quantity" Type="Int32" />
<asp:Parameter Name="original_Price" Type="Decimal" />
<asp:Parameter Name="original_OrderID" Type="Int32" />
<asp:Parameter Name="original_Total" Type="Decimal" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="ProductID" />
<asp:Parameter Name="UserName" />
<asp:Parameter Name="InsertDate" />
<asp:Parameter Name="Quantity" />
<asp:Parameter Name="Price" />
<asp:Parameter Name="OrderID" />
<asp:Parameter Name="Total" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="ProductID" Type="Int32" />
<asp:Parameter Name="UserName" Type="String" />
<asp:Parameter Name="InsertDate" Type="DateTime" />
<asp:Parameter Name="Quantity" Type="Int32" />
<asp:Parameter Name="Price" Type="Decimal" />
<asp:Parameter Name="OrderID" Type="Int32" />
<asp:Parameter Name="Total" Type="Decimal" />
<asp:Parameter Name="original_CartID" Type="Int32" />
<asp:Parameter Name="original_ProductID" Type="Int32" />
<asp:Parameter Name="original_UserName" Type="String" />
<asp:Parameter Name="original_InsertDate" Type="DateTime" />
<asp:Parameter Name="original_Quantity" Type="Int32" />
<asp:Parameter Name="original_Price" Type="Decimal" />
<asp:Parameter Name="original_OrderID" Type="Int32" />
<asp:Parameter Name="original_Total" Type="Decimal" />
</UpdateParameters>
</asp:SqlDataSource>
Do guide me in this i dont know what they mean by the error.This is for the admin who can update or delete in the shopping cart
problem in your update command
UpdateCommand="UPDATE [ShoppingCart] SET [ProductID] = #ProductID, [UserName] = #UserName, [InsertDate] = #InsertDate, [Quantity] = #Quantity, [Price] = #Price, [OrderID] = #OrderID, [Total]= #Total, WHERE [CartID] = #original_CartID AND [ProductID] = #original_ProductID AND [UserName] = #original_UserName AND [InsertDate] = #original_InsertDate AND [Quantity] = #original_Quantity AND [Price] = #original_Price AND [OrderID] = #original_OrderID AND [Total]= #Total">
in query ther is comma before WHERE
find this,
[Total]= #Total, WHERE [CartID] = #original_CartID