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>
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.
I couldn't figure out how to fix this error:
Exception Details: System.Data.OleDb.OleDbException: No value given for one or
more required parameters.
I get this error whenever I try to update a user's information. I've been trying to figure out what's missing in the code and been searching for a solution. I've found similar questions like this, but it's kind of different because I'm not quite sure which one I should remove.
Here's code:
<asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/Geebiz.mdb"
DeleteCommand="DELETE FROM [tbl_Student] WHERE [Student_Num] = ?"
InsertCommand="INSERT INTO [tbl_Student] ([Student_Num], [Team_ID], [Team_Status],
[Student_University], [Student_UniCountry], [Student_FullName], [Student_PreferredName],
[Student_Email], [Student_Email2], [Student_Address1], [Student_Address2],
[Student_Address3], [Student_AddressCity], [Student_AddressCountry],
[Student_AddressPostcode], [Student_MobileCountryList], [Student_MobilePhone],
[Student_Facebook], [Student_Skype], [Student_Gender], [Student_CourseRep],
[Student_English], [Student_Broadband], [Student_CompAccess], [Recommender_Name],
[Recommender_Email], [Recommender_Phone], [Student_Status])
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
SelectCommand="SELECT * FROM [tbl_Student] WHERE ([Student_Num] = ?)"
UpdateCommand="UPDATE [tbl_Student] SET [Team_ID] = ?, [Team_Status] = ?,
[Student_University] = ?, [Student_UniCountry] = ?, [Student_FullName] = ?,
[Student_PreferredName] = ?, [Student_Email] = ?, [Student_Email2] = ?,
[Student_Address1] = ?, [Student_Address2] = ?, [Student_Address3] = ?,
[Student_AddressCity] = ?, [Student_AddressCountry] = ?, [Student_AddressPostcode] = ?,
[Student_MobilePhoneCountryCode] = ?, [Student_MobileCountryList] = ?, [Student_Facebook] =
?, [Student_Skype] = ?, [Student_Gender] = ?, [Student_CourseRep] = ?, [Student_English] = ?,
[Student_Broadband] = ?, [Student_CompAccess] = ?, [Recommender_Name] = ?,
[Recommender_Email] = ?, [Recommender_Phone] = ?, [Student_Status] = ?
WHERE [Student_Num] = ?">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="Student_Num"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="Student_Num" Type="Int32" />
</DeleteParameters>
I think the error is somewhere around here:
<UpdateParameters>
<asp:Parameter Name="Team_ID" Type="Int32" />
<asp:Parameter Name="Team_Status" Type="String" />
<asp:Parameter Name="Student_University" Type="String" />
<asp:Parameter Name="Student_UniCountry" Type="String" />
<asp:Parameter Name="Student_FullName" Type="String" />
<asp:Parameter Name="Student_PreferredName" Type="String" />
<asp:Parameter Name="Student_Email" Type="String" />
<asp:Parameter Name="Student_Email2" Type="String" />
<asp:Parameter Name="Student_Address1" Type="String" />
<asp:Parameter Name="Student_Address2" Type="String" />
<asp:Parameter Name="Student_Address3" Type="String" />
<asp:Parameter Name="Student_AddressCity" Type="String" />
<asp:Parameter Name="Student_AddressCountry" Type="String" />
<asp:Parameter Name="Student_AddressPostcode" Type="String" />
<asp:Parameter Name="Student_MobileCountryList" Type="String" />
<asp:Parameter Name="Student_MobilePhone" Type="String" />
<asp:Parameter Name="Student_Facebook" Type="String" />
<asp:Parameter Name="Student_Skype" Type="String" />
<asp:Parameter Name="Student_Gender" Type="String" />
<asp:Parameter Name="Student_CourseRep" Type="String" />
<asp:Parameter Name="Student_English" Type="String" />
<asp:Parameter Name="Student_Broadband" Type="String" />
<asp:Parameter Name="Student_CompAccess" Type="String" />
<asp:Parameter Name="Recommender_Name" Type="String" />
<asp:Parameter Name="Recommender_Email" Type="String" />
<asp:Parameter Name="Recommender_Phone" Type="String" />
<asp:Parameter Name="Student_Status" Type="String" />
<asp:Parameter Name="Student_Num" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="Student_Num" Type="Int32" />
<asp:Parameter Name="Team_ID" Type="Int32" />
<asp:Parameter Name="Team_Status" Type="String" />
<asp:Parameter Name="Student_University" Type="String" />
<asp:Parameter Name="Student_UniCountry" Type="String" />
<asp:Parameter Name="Student_FullName" Type="String" />
<asp:Parameter Name="Student_PreferredName" Type="String" />
<asp:Parameter Name="Student_Email" Type="String" />
<asp:Parameter Name="Student_Email2" Type="String" />
<asp:Parameter Name="Student_Address1" Type="String" />
<asp:Parameter Name="Student_Address2" Type="String" />
<asp:Parameter Name="Student_Address3" Type="String" />
<asp:Parameter Name="Student_AddressCity" Type="String" />
<asp:Parameter Name="Student_AddressCountry" Type="String" />
<asp:Parameter Name="Student_AddressPostcode" Type="String" />
<asp:Parameter Name="Student_MobileCountryList" Type="String" />
<asp:Parameter Name="Student_MobilePhone" Type="String" />
<asp:Parameter Name="Student_Facebook" Type="String" />
<asp:Parameter Name="Student_Skype" Type="String" />
<asp:Parameter Name="Student_Gender" Type="String" />
<asp:Parameter Name="Student_CourseRep" Type="String" />
<asp:Parameter Name="Student_English" Type="String" />
<asp:Parameter Name="Student_Broadband" Type="String" />
<asp:Parameter Name="Student_CompAccess" Type="String" />
<asp:Parameter Name="Recommender_Name" Type="String" />
<asp:Parameter Name="Recommender_Email" Type="String" />
<asp:Parameter Name="Recommender_Phone" Type="String" />
<asp:Parameter Name="Student_Status" Type="String" />
</InsertParameters>
</asp:AccessDataSource>
<asp:Label ID="lbl_message2" runat="server" ForeColor="Black">
Please select a student from the left column first, before you click the
continue button in order to update the student detail.
</asp:Label><br />
<asp:Button ID="btn_continue" runat="server" Text="Continue" /><br /><br />
The detail of the student you have selected is shown below:<br />
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="Student_Num" DataSourceID="AccessDataSource2" Height="32px" Width="536px">
<Fields>
<asp:BoundField DataField="Student_Num" HeaderText="Student_Num" InsertVisible="False"
ReadOnly="True" SortExpression="Student_Num" />
<asp:BoundField DataField="Team_ID" HeaderText="Team_ID" SortExpression="Team_ID" />
<asp:BoundField DataField="Team_Status" HeaderText="Team_Status" SortExpression="Team_Status" />
<asp:BoundField DataField="Student_University" HeaderText="Student_University"
SortExpression="Student_University" />
<asp:BoundField DataField="Student_UniCountry" HeaderText="Student_UniCountry"
SortExpression="Student_UniCountry" />
<asp:BoundField DataField="Student_FullName" HeaderText="Student_FullName"
SortExpression="Student_FullName" />
<asp:BoundField DataField="Student_PreferredName" HeaderText="Student_PreferredName"
SortExpression="Student_PreferredName" />
<asp:BoundField DataField="Student_Email" HeaderText="Student_Email"
SortExpression="Student_Email" />
<asp:BoundField DataField="Student_Email2" HeaderText="Student_Email2"
SortExpression="Student_Email2" />
<asp:BoundField DataField="Student_Address1" HeaderText="Student_Address1"
SortExpression="Student_Address1" />
<asp:BoundField DataField="Student_Address2" HeaderText="Student_Address2"
SortExpression="Student_Address2" />
<asp:BoundField DataField="Student_Address3" HeaderText="Student_Address3"
SortExpression="Student_Address3" />
<asp:BoundField DataField="Student_AddressCity" HeaderText="Student_AddressCity"
SortExpression="Student_AddressCity" />
<asp:BoundField DataField="Student_AddressCountry" HeaderText="Student_AddressCountry"
SortExpression="Student_AddressCountry" />
<asp:BoundField DataField="Student_AddressPostcode" HeaderText="Student_AddressPostcode"
SortExpression="Student_AddressPostcode" />
<asp:BoundField DataField="Student_MobileCountryList" HeaderText="Student_MobileCountryList"
SortExpression="Student_MobileCountryList" />
<asp:BoundField DataField="Student_MobilePhone" HeaderText="Student_MobilePhone"
SortExpression="Student_MobilePhone" />
<asp:BoundField DataField="Student_Facebook" HeaderText="Student_Facebook"
SortExpression="Student_Facebook" />
<asp:BoundField DataField="Student_Skype" HeaderText="Student_Skype"
SortExpression="Student_Skype" />
<asp:BoundField DataField="Student_Gender" HeaderText="Student_Gender"
SortExpression="Student_Gender" />
<asp:BoundField DataField="Student_CourseRep" HeaderText="Student_CourseRep"
SortExpression="Student_CourseRep" />
<asp:BoundField DataField="Student_English" HeaderText="Student_English"
SortExpression="Student_English" />
<asp:BoundField DataField="Student_Broadband" HeaderText="Student_Broadband"
SortExpression="Student_Broadband" />
<asp:BoundField DataField="Student_CompAccess" HeaderText="Student_CompAccess"
SortExpression="Student_CompAccess" />
<asp:BoundField DataField="Recommender_Name" HeaderText="Recommender_Name"
SortExpression="Recommender_Name" />
<asp:BoundField DataField="Recommender_Email" HeaderText="Recommender_Email"
SortExpression="Recommender_Email" />
<asp:BoundField DataField="Recommender_Phone" HeaderText="Recommender_Phone"
SortExpression="Recommender_Phone" />
<asp:BoundField DataField="Student_Status" HeaderText="Student_Status"
SortExpression="Student_Status" />
<asp:CommandField ShowEditButton="True" />
</Fields>
</asp:DetailsView>
The order of the parameter in the UpdateCommand should be same as in the UpdateParameters. Also, check your [Student_MobilePhoneCountryCode] is missing from the UpdateParameter list.
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 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.
<asp:AccessDataSource ID="productsubtype" Runat="server" DataFile="~/access_db/db_tables.mdb"
SelectCommand="SELECT [type], [id],[subtype] FROM [prod_subtype]"
UpdateCommand="UPDATE [prod_subtype] SET [subtype]=#subtype WHERE [id]=#id"
DeleteCommand="DELETE FROM [prod_subtype] WHERE [id]=#id"
FilterExpression="type='{0}'">
<UpdateParameters>
<asp:Parameter Name="subtype" Type="string" />
</UpdateParameters>
<DeleteParameters>
<asp:Parameter Name="id" Type="string" />
</DeleteParameters>
<FilterParameters>
<asp:ControlParameter Name="type" DefaultValue="-1"
Type="String" ControlID="gdproducttype"
PropertyName="SelectedValue"></asp:ControlParameter>
</FilterParameters>
</asp:AccessDataSource>
When i press delete button in gridview i am getting error
Try changing your UpdateParameters to the following:
<UpdateParameters>
<asp:Parameter Name="id" Type="string" />
<asp:Parameter Name="subtype" Type="string" />
</UpdateParameters>