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.
Related
I have a gridview, in the gridview task, I choose Edit Column-> Selected Fields->Command Field.select insert button to True. And the New link field appear, and I check the HTML Source,
look like necessary codes are there, but when I click on the "New" link field, no response at all, but update is ok for me, delete I have not tested yet.
Below are codes for the gridview and sqldatasource :
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="agreement_no,id" Font-Size="9pt" DataSourceID="SqlDataSource1" OnRowUpdated="GridView1_RowUpdated" OnRowUpdating="GridView1_RowUpdating" OnRowCreated="GridView1_RowCreated">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True"></asp:CommandField>
<asp:BoundField DataField="agreement_no" HeaderText="agreement_no" ReadOnly="True" SortExpression="agreement_no"></asp:BoundField>
<asp:TemplateField HeaderText="status" SortExpression="status">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2" DataTextField="status" DataValueField="status" SelectedValue='<%# Bind("status") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:GPGConnectionString %>" SelectCommand="SELECT DISTINCT [status] FROM [deal_master]"></asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="sales_person" HeaderText="sales_person" SortExpression="sales_person"></asp:BoundField>
<asp:BoundField DataField="swap_carrier" HeaderText="swap_carrier" SortExpression="swap_carrier"></asp:BoundField>
<asp:BoundField DataField="start_pos" HeaderText="start_pos" SortExpression="start_pos"></asp:BoundField>
<asp:BoundField DataField="end_pos" HeaderText="end_pos" SortExpression="end_pos"></asp:BoundField>
<asp:BoundField DataField="swap_commitment" HeaderText="swap_commitment" SortExpression="swap_commitment"></asp:BoundField>
<asp:BoundField DataField="zone" HeaderText="zone" SortExpression="zone"></asp:BoundField>
<asp:BoundField DataField="target_minutes" HeaderText="target_minutes" SortExpression="target_minutes"></asp:BoundField>
<asp:BoundField DataField="target_sell_rate" HeaderText="target_sell_rate" SortExpression="target_sell_rate"></asp:BoundField>
<asp:BoundField DataField="target_buy_rate" HeaderText="target_buy_rate" SortExpression="target_buy_rate"></asp:BoundField>
<asp:BoundField ConvertEmptyStringToNull="false" DataField="supplier_interconnect" HeaderText="supplier_interconnect" SortExpression="supplier_interconnect"></asp:BoundField>
<asp:BoundField ConvertEmptyStringToNull="false" DataField="customer_interconnect" HeaderText="customer_interconnect" SortExpression="customer_interconnect"></asp:BoundField>
<asp:BoundField DataField="target_sales" HeaderText="target_sales" SortExpression="target_sales"></asp:BoundField>
<asp:BoundField DataField="target_cost" HeaderText="target_cost" SortExpression="target_cost"></asp:BoundField>
<asp:BoundField DataField="target_profit" HeaderText="target_profit" SortExpression="target_profit"></asp:BoundField>
<asp:BoundField DataField="lcr_zone" HeaderText="lcr_zone" SortExpression="lcr_zone"></asp:BoundField>
<asp:BoundField DataField="id" HeaderText="id" SortExpression="id" ReadOnly="True"></asp:BoundField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:GPGConnectionString %>" DeleteCommand="DELETE FROM [deal_master] WHERE [agreement_no] = #agreement_no AND [id] = #id" InsertCommand="INSERT INTO [deal_master] ([agreement_no], [status], [sales_person], [swap_carrier], [start_pos], [end_pos], [swap_commitment], [zone], [target_minutes], [target_sell_rate], [target_buy_rate], [supplier_interconnect], [customer_interconnect], [target_sales], [target_cost], [target_profit], [lcr_zone], [id]) VALUES (#agreement_no, #status, #sales_person, #swap_carrier, #start_pos, #end_pos, #swap_commitment, #zone, #target_minutes, #target_sell_rate, #target_buy_rate, #supplier_interconnect, #customer_interconnect, #target_sales, #target_cost, #target_profit, #lcr_zone, #id)" SelectCommand="SELECT [agreement_no], [status], [sales_person], [swap_carrier], [start_pos], [end_pos], [swap_commitment], [zone], [target_minutes], [target_sell_rate], [target_buy_rate], [supplier_interconnect], [customer_interconnect], [target_sales], [target_cost], [target_profit], [lcr_zone], [id] FROM [deal_master]" UpdateCommand="UPDATE [deal_master] SET [status] = #status, [sales_person] = #sales_person, [swap_carrier] = #swap_carrier, [start_pos] = #start_pos, [end_pos] = #end_pos, [swap_commitment] = #swap_commitment, [zone] = #zone, [target_minutes] = #target_minutes, [target_sell_rate] = #target_sell_rate, [target_buy_rate] = #target_buy_rate, [supplier_interconnect] = #supplier_interconnect, [customer_interconnect] = #customer_interconnect, [target_sales] = #target_sales, [target_cost] = #target_cost, [target_profit] = #target_profit, [lcr_zone] = #lcr_zone WHERE [agreement_no] = #agreement_no AND [id] = #id">
<DeleteParameters>
<asp:Parameter Name="agreement_no" Type="String" />
<asp:Parameter Name="id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="agreement_no" Type="String" />
<asp:Parameter Name="status" Type="String" />
<asp:Parameter Name="sales_person" Type="String" />
<asp:Parameter Name="swap_carrier" Type="String" />
<asp:Parameter Name="start_pos" Type="Decimal" />
<asp:Parameter Name="end_pos" Type="Decimal" />
<asp:Parameter Name="swap_commitment" Type="String" />
<asp:Parameter Name="zone" Type="String" />
<asp:Parameter Name="target_minutes" Type="Decimal" />
<asp:Parameter Name="target_sell_rate" Type="Decimal" />
<asp:Parameter Name="target_buy_rate" Type="Decimal" />
<asp:Parameter Name="supplier_interconnect" Type="String" />
<asp:Parameter ConvertEmptyStringToNull="false" Name="customer_interconnect" Type="String" />
<asp:Parameter Name="target_sales" Type="Decimal" />
<asp:Parameter Name="target_cost" Type="Decimal" />
<asp:Parameter Name="target_profit" Type="Decimal" />
<asp:Parameter Name="lcr_zone" Type="String" />
<asp:Parameter Name="id" Type="Int32" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="status" Type="String" />
<asp:Parameter Name="sales_person" Type="String" />
<asp:Parameter Name="swap_carrier" Type="String" />
<asp:Parameter Name="start_pos" Type="Decimal" />
<asp:Parameter Name="end_pos" Type="Decimal" />
<asp:Parameter Name="swap_commitment" Type="String" />
<asp:Parameter Name="zone" Type="String" />
<asp:Parameter Name="target_minutes" Type="Decimal" />
<asp:Parameter Name="target_sell_rate" Type="Decimal" />
<asp:Parameter Name="target_buy_rate" Type="Decimal" />
<asp:Parameter ConvertEmptyStringToNull="false" Name="supplier_interconnect" Type="String" />
<asp:Parameter ConvertEmptyStringToNull="false" Name="customer_interconnect" Type="String" />
<asp:Parameter Name="target_sales" Type="Decimal" />
<asp:Parameter Name="target_cost" Type="Decimal" />
<asp:Parameter Name="target_profit" Type="Decimal" />
<asp:Parameter Name="lcr_zone" Type="String" />
<asp:Parameter Name="agreement_no" Type="String" />
<asp:Parameter Name="id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:GPGConnectionString %>" SelectCommand="SELECT DISTINCT [agreement_no] FROM [deal_master] ORDER BY [agreement_no]"></asp:SqlDataSource>
<br />
<br />
<div>
</div>
enter image description here
my question is : what is the actions or setting I missed?
I want to know what steps I missed?
My objective is : I want to click on the "New" linkfield then 1 empty row appear, then I input the value in the new created row and I can save it or cancel it
If you look at the documentation for the GridView control, it says:
Inserting records into the data source is not directly supported by the GridView control. However, it is possible to insert records by using the GridView control in conjunction with the DetailsView or FormView control. For more information, see DetailsView or FormView, respectively.
Additionally, the CommandField documentation states about the ShowInsertButton property:
This property applies only to data-bound controls that support insert operations, such as the DetailsView control.
So, you'll need to create your own form separately, or leverage a DetailsView or FormView. Or better yet: ditch Web Forms altogether if you can, as it's a dead platform, as I explain on my blog.
<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] = ?
">
I am trying to update a table that has and indentity column. So when I try to update a row in gridview I get the following error "Cannot update identity column 'ManufactureID'.]" I know you can insert the updated row and then delete the old row.
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="Name" DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display.">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" />
<asp:BoundField DataField="ManufactureID" HeaderText="ManufactureID" ReadOnly="True" SortExpression="ManufactureID" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
<asp:BoundField DataField="Providence" HeaderText="Providence" SortExpression="Providence" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="ZipCode" HeaderText="ZipCode" SortExpression="ZipCode" />
<asp:BoundField DataField="Country" HeaderText="Country" SortExpression="Country" />
<asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
<asp:BoundField DataField="Fax" HeaderText="Fax" SortExpression="Fax" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:GreatGrizzlyConnectionString1 %>" DeleteCommand="DELETE FROM [Manufacturer] WHERE [Name] = #Name" InsertCommand="INSERT INTO [Manufacturer] ([Name], [Address], [Providence], [City], [ZipCode], [Country], [Phone], [Fax], [Email]) VALUES (#Name, #Address, #Providence, #City, #ZipCode, #Country, #Phone, #Fax, #Email)" ProviderName="<%$ ConnectionStrings:SQLTestConnectionString1.ProviderName %>" SelectCommand="SELECT [ManufactureID], [Name], [Address], [Providence], [City], [ZipCode], [Country], [Phone], [Fax], [Email] FROM [Manufacturer]" UpdateCommand="UPDATE [Manufacturer] SET [ManufactureID] = #ManufactureID, [Address] = #Address, [Providence] = #Providence, [City] = #City, [ZipCode] = #ZipCode, [Country] = #Country, [Phone] = #Phone, [Fax] = #Fax, [Email] = #Email WHERE [Name] = #Name">
<DeleteParameters>
<asp:Parameter Name="Name" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="Providence" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="ZipCode" Type="String" />
<asp:Parameter Name="Country" Type="String" />
<asp:Parameter Name="Phone" Type="String" />
<asp:Parameter Name="Fax" Type="String" />
<asp:Parameter Name="Email" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="ManufactureID" Type="Int32" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="Providence" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="ZipCode" Type="String" />
<asp:Parameter Name="Country" Type="String" />
<asp:Parameter Name="Phone" Type="String" />
<asp:Parameter Name="Fax" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="Name" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
The statement specified in the UpdateCommand attribute of your <asp:SqlDataSource> tag tries to set the [ManufactureID], that's why you're getting the error:
UpdateCommand="UPDATE [Manufacturer] SET [ManufactureID] = #ManufactureID, [Address] = #Address, [Providence] = #Providence, [City] = #City, [ZipCode] = #ZipCode, [Country] = #Country, [Phone] = #Phone, [Fax] = #Fax, [Email] = #Email WHERE [Name] = #Name"
You need to remove [ManufactureID] = #ManufactureID, and also remove <asp:Parameter Name="ManufactureID" Type="Int32" /> from under <UpdateParameters>, that should do the trick.
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
Im using:
Visual Web Developer 2009
Access 2007
I am trying to insert into a products table, however i keep recieveing the error:
"Data type mismatch in criteria expression."
The Edit and Delete sections work fine..
Edit Products
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="product_id" DataSourceID="AccessDataSource1" DefaultMode="Insert"
Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="product_id" HeaderText="product_id"
InsertVisible="False" ReadOnly="True" SortExpression="product_id" />
<asp:BoundField DataField="product_name" HeaderText="product_name"
SortExpression="product_name" />
<asp:BoundField DataField="product_desc" HeaderText="product_desc"
SortExpression="product_desc" />
<asp:BoundField DataField="product_cost" HeaderText="product_cost"
SortExpression="product_cost" />
<asp:BoundField DataField="product_amount" HeaderText="product_amount"
SortExpression="product_amount" />
<asp:BoundField DataField="category_id" HeaderText="category_id"
SortExpression="category_id" />
<asp:CommandField ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/Fandangles.mdb"
DeleteCommand="DELETE FROM [product] WHERE [product_id] = ?"
InsertCommand="INSERT INTO [product] ([product_name], [product_desc], [product_cost], [product_amount], [category_id]) VALUES (?, ?, ?, ?, ?)"
SelectCommand="SELECT * FROM [product]"
UpdateCommand="UPDATE [product] SET [product_name] = ?, [product_desc] = ?, [product_cost] = ?, [product_amount] = ?, [category_id] = ? WHERE [product_id] = ?">
<DeleteParameters>
<asp:Parameter Name="product_id" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="product_name" Type="String" />
<asp:Parameter Name="product_desc" Type="String" />
<asp:Parameter Name="product_cost" Type="Decimal" />
<asp:Parameter Name="product_amount" Type="Int32" />
<asp:Parameter Name="category_id" Type="Int32" />
<asp:Parameter Name="product_id" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="product_id" Type="Int32" />
<asp:Parameter Name="product_name" Type="String" />
<asp:Parameter Name="product_desc" Type="String" />
<asp:Parameter Name="product_cost" Type="Decimal" />
<asp:Parameter Name="product_amount" Type="Int32" />
<asp:Parameter Name="category_id" Type="Int32" />
</InsertParameters>
</asp:AccessDataSource>
</p>
</asp:Content>
DB: Access DB
product_id - Autonumber
product_name - Text
product_desc - Text
product_cost - Currency
product_amount - Number
category_id - Number - This is a lookup field
Any ideas?
Do you really need to pass your primary key "product_id" into the insert? If its an identity / PK its not needed.
Its not a param in your insert SQL yet it is a param in the datasoruces insert params.
Try this
<InsertParameters>
<asp:Parameter Name="product_id" Type="Int32" />
<asp:Parameter Name="product_name" Type="String" />
<asp:Parameter Name="product_desc" Type="String" />
<asp:Parameter Name="product_cost" Type="Decimal" />
<asp:Parameter Name="product_amount" Type="Int32" />
<asp:Parameter Name="category_id" Type="Int32" />
</InsertParameters>