asp.net access database not updating - asp.net

I am trying to update values in my access database, however it does not work in some cases.
The code :
<form id="form1" runat="server">
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/Database1.mdb"
DeleteCommand="UPDATE DT_Person SET Deleted = NOW() WHERE (Person_Ref = ?)"
InsertCommand="INSERT INTO [DT_Person] ([Person_Ref], [Created], [Updated], [Deleted], [Person_Name], [Person_No]) VALUES (?, ?, ?, ?, ?, ?)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT * FROM [DT_Person]"
UpdateCommand="UPDATE DT_Person SET Updated = NOW(), Person_Name = ?, Person_No = ? WHERE (Person_Ref = ?)">
<DeleteParameters>
<asp:Parameter Name="original_Person_Ref" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Created" Type="DateTime" />
<asp:Parameter Name="Updated" Type="DateTime" />
<asp:Parameter Name="Deleted" Type="DateTime" />
<asp:Parameter Name="Person_Name" Type="String" />
<asp:Parameter Name="Person_No" Type="String" />
<asp:Parameter Name="original_Person_Ref" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="Person_Ref" Type="Int32" />
<asp:Parameter Name="Created" Type="DateTime" />
<asp:Parameter Name="Updated" Type="DateTime" />
<asp:Parameter Name="Deleted" Type="DateTime" />
<asp:Parameter Name="Person_Name" Type="String" />
<asp:Parameter Name="Person_No" Type="String" />
</InsertParameters>
</asp:AccessDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" BackColor="White"
BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3"
DataKeyNames="Person_Ref" DataSourceID="AccessDataSource1">
<RowStyle ForeColor="#000066" />
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
ShowSelectButton="True" />
<asp:BoundField DataField="Person_Ref" HeaderText="Person_Ref"
InsertVisible="False" ReadOnly="True" SortExpression="Person_Ref" />
<asp:BoundField DataField="Created" HeaderText="Created"
SortExpression="Created" />
<asp:BoundField DataField="Updated" HeaderText="Updated"
SortExpression="Updated" />
<asp:BoundField DataField="Deleted" HeaderText="Deleted"
SortExpression="Deleted" />
<asp:BoundField DataField="Person_Name" HeaderText="Person_Name"
SortExpression="Person_Name" />
<asp:BoundField DataField="Person_No" HeaderText="Person_No"
SortExpression="Person_No" />
</Columns>
As you can see, the delete command
(DeleteCommand="UPDATE DT_Person SET Deleted = NOW() WHERE (Person_Ref = ?)" )
is really an update statement and this works fine . However the actual update statement does not work on the web page. The weird thing is, if you test the query in the 'query builder' it works fine.
Really need some help here.
TIA
P.S. Im using Visual Studio 2008 and using the data source builder each time

Windows 7 (if that's what you're using) has been known to make a copy of Access databases down in the Debug files and use the copy for all data changes. You might want to check that the database you are actually accessing is the copy you think it is.
Do a search for files with the same name across your whole development machine. You might be surprised what turns up.

Related

How to make new command work in gridview asp.net

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.

Gridview Data Bind Error

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.

asp.net fail to access value when set read-only to true

My update sql procedure is
ALTER PROCEDURE [dbo].[usp_update]
#ID uniqueidentifier,
#Period nvarchar(6),
#News nvarchar(max),
#Editor nvarchar(30)
as
begin
update table1
set News= #News, Editor=#Editor, LastRevNT=getdate()
where ID=#ID and Period=#Period
end
my asp.net grid view is
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True">
<Columns>
asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="Period" HeaderText="Period" SortExpression="Period" ReadOnly="True"/>
<asp:BoundField DataField="News" HeaderText="News" SortExpression="News" />
<asp:BoundField DataField="Editor" HeaderText="Editor" SortExpression="Editor" ReadOnly="True" />
</Columns>
datasource is
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="usp_select" SelectCommandType="StoredProcedure" UpdateCommand="usp_update" UpdateCommandType="StoredProcedure">
<SelectParameters>
<asp:SessionParameter DefaultValue="" Name="ID" SessionField="SelectedID" dbType="guid" />
</SelectParameters>
<UpdateParameters>
<asp:SessionParameter DefaultValue="" Name="ID" SessionField="SelectedID" dbType="guid" />
<asp:SessionParameter DefaultValue="" Name="Editor" SessionField="SelectedEditor" dbType="string"/>
<asp:Parameter Name="Period" Type="String" />
<asp:Parameter Name="News" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
Problem is that when I update the table, I need both ID and [Period] to get the unique record.
And in gridview, I don't want to [period] to be modified. When I set the bound for period to be read-only, then I fail to access the value of period, thus fail to update the right record.
I wonder how I can handle the problem?
Thanks for advice!
I added DataKeyNames = "ID,Period" in my aspgridview, and it works ok now. Thanks for advice!

detailed information for each entry in gridview

So i have made a Web Form with a dropdownlist which contains different classes in school and if you select one you get all the students of the selected class in the GridView below. So what i want to make now is, that if i click on a student it should open a more detailed page about the student, but i have no clues how to do this. I get all my data of a .mdf database file.
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="schueler.aspx.cs" Inherits="ASPXUebung.schueler" %>
<asp:DropDownList ID="selectklassen" runat="server" DataSourceID="SqlDataSource1klassenselect" DataTextField="K_Bez" DataValueField="K_ID" AutoPostBack="true"></asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1klassenselect" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [K_Bez], [K_ID] FROM [klassen] ORDER BY [K_Bez]"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="S_SCHNR" DataSourceID="SqlDataSource1schueler">
<Columns>
<asp:BoundField DataField="S_SCHNR" HeaderText="S_SCHNR" ReadOnly="True" SortExpression="S_SCHNR" />
<asp:BoundField DataField="S_Name" HeaderText="S_Name" SortExpression="S_Name" />
<asp:BoundField DataField="S_Vorname" HeaderText="S_Vorname" SortExpression="S_Vorname" />
<asp:BoundField DataField="S_Gebdat" HeaderText="S_Gebdat" SortExpression="S_Gebdat" />
<asp:BoundField DataField="S_Adresse" HeaderText="S_Adresse" SortExpression="S_Adresse" />
<asp:BoundField DataField="S_K_Klasse" HeaderText="S_K_Klasse" SortExpression="S_K_Klasse" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1schueler" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" DeleteCommand="DELETE FROM [schueler] WHERE [S_SCHNR] = #original_S_SCHNR AND (([S_Name] = #original_S_Name) OR ([S_Name] IS NULL AND #original_S_Name IS NULL)) AND (([S_Vorname] = #original_S_Vorname) OR ([S_Vorname] IS NULL AND #original_S_Vorname IS NULL)) AND (([S_Gebdat] = #original_S_Gebdat) OR ([S_Gebdat] IS NULL AND #original_S_Gebdat IS NULL)) AND (([S_Adresse] = #original_S_Adresse) OR ([S_Adresse] IS NULL AND #original_S_Adresse IS NULL)) AND (([S_K_Klasse] = #original_S_K_Klasse) OR ([S_K_Klasse] IS NULL AND #original_S_K_Klasse IS NULL))" InsertCommand="INSERT INTO [schueler] ([S_SCHNR], [S_Name], [S_Vorname], [S_Gebdat], [S_Adresse], [S_K_Klasse]) VALUES (#S_SCHNR, #S_Name, #S_Vorname, #S_Gebdat, #S_Adresse, #S_K_Klasse)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [schueler] WHERE ([S_K_Klasse] = #S_K_Klasse)" UpdateCommand="UPDATE [schueler] SET [S_Name] = #S_Name, [S_Vorname] = #S_Vorname, [S_Gebdat] = #S_Gebdat, [S_Adresse] = #S_Adresse, [S_K_Klasse] = #S_K_Klasse WHERE [S_SCHNR] = #original_S_SCHNR AND (([S_Name] = #original_S_Name) OR ([S_Name] IS NULL AND #original_S_Name IS NULL)) AND (([S_Vorname] = #original_S_Vorname) OR ([S_Vorname] IS NULL AND #original_S_Vorname IS NULL)) AND (([S_Gebdat] = #original_S_Gebdat) OR ([S_Gebdat] IS NULL AND #original_S_Gebdat IS NULL)) AND (([S_Adresse] = #original_S_Adresse) OR ([S_Adresse] IS NULL AND #original_S_Adresse IS NULL)) AND (([S_K_Klasse] = #original_S_K_Klasse) OR ([S_K_Klasse] IS NULL AND #original_S_K_Klasse IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_S_SCHNR" Type="Int16" />
<asp:Parameter Name="original_S_Name" Type="String" />
<asp:Parameter Name="original_S_Vorname" Type="String" />
<asp:Parameter Name="original_S_Gebdat" Type="DateTime" />
<asp:Parameter Name="original_S_Adresse" Type="String" />
<asp:Parameter Name="original_S_K_Klasse" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="S_SCHNR" Type="Int16" />
<asp:Parameter Name="S_Name" Type="String" />
<asp:Parameter Name="S_Vorname" Type="String" />
<asp:Parameter Name="S_Gebdat" Type="DateTime" />
<asp:Parameter Name="S_Adresse" Type="String" />
<asp:Parameter Name="S_K_Klasse" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="selectklassen" Name="S_K_Klasse" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="S_Name" Type="String" />
<asp:Parameter Name="S_Vorname" Type="String" />
<asp:Parameter Name="S_Gebdat" Type="DateTime" />
<asp:Parameter Name="S_Adresse" Type="String" />
<asp:Parameter Name="S_K_Klasse" Type="String" />
<asp:Parameter Name="original_S_SCHNR" Type="Int16" />
<asp:Parameter Name="original_S_Name" Type="String" />
<asp:Parameter Name="original_S_Vorname" Type="String" />
<asp:Parameter Name="original_S_Gebdat" Type="DateTime" />
<asp:Parameter Name="original_S_Adresse" Type="String" />
<asp:Parameter Name="original_S_K_Klasse" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
Make the student name column a Hyperlink column like this:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="S_SCHNR" DataSourceID="SqlDataSource1schueler">
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="S_SCHNR"
DataNavigateUrlFormatString="StudentInfo.aspx?id={0}
DataTextField="S_Name" "/>
<asp:BoundField DataField="S_SCHNR" HeaderText="S_SCHNR" ReadOnly="True" SortExpression="S_SCHNR" />
<asp:BoundField DataField="S_Name" HeaderText="S_Name" SortExpression="S_Name" />
<asp:BoundField DataField="S_Vorname" HeaderText="S_Vorname" SortExpression="S_Vorname" />
<asp:BoundField DataField="S_Gebdat" HeaderText="S_Gebdat" SortExpression="S_Gebdat" />
<asp:BoundField DataField="S_Adresse" HeaderText="S_Adresse" SortExpression="S_Adresse" />
<asp:BoundField DataField="S_K_Klasse" HeaderText="S_K_Klasse" SortExpression="S_K_Klasse" />
</Columns>
</asp:GridView>
Make another web page called StudentInfo.aspx. On that page, display the data using a DetailsView control, a SqlDataSource control and the QueryString parameter. Here's an example of how to do that: http://msdn.microsoft.com/en-us/library/xt50s8kz(v=vs.100).aspx
A more convenient way to do this without creating a new page would be to populate the data into a Bootstrap modal like this. It uses UpdatePanel, which may or may not be something you want to use though.
Add the Detail Event to the Gridview.
Create a div for the Bootstrap modal with a FormView
Call the jQuery from the C# code behind to populate the data in the FormView with the ID from the GridView.

Visual Web Developer 2008 - ASP - Formview and Inserts

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>

Resources