AccessDataSource doesnt pick up edited data from GridView and it doesnt save it to database.
Can someone tell what am I doing wrong here? Updating the database doesnt work.
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/baza.mdb"
SelectCommand="SELECT * FROM [users]"
DeleteCommand="DELETE FROM users WHERE (username = ?)"
InsertCommand="INSERT INTO users(username, [password], isAdmin) VALUES (?, ?, ?)"
OldValuesParameterFormatString="original_{0}"
UpdateCommand="UPDATE [users] SET [username] = ?, [password] = ?, [isAdmin] = ? WHERE ([username] = ?)">
<DeleteParameters>
<asp:Parameter DbType="String" Name="username" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter DbType="String" Name="username" />
<asp:Parameter DbType="String" Name="password" />
<asp:Parameter DbType="String" Name="isAdmin" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter DbType="String" Name="username" />
<asp:Parameter DbType="String" Name="password" />
<asp:Parameter DbType="String" Name="isAdmin" />
<asp:Parameter DbType="String" Name="original_username" />
</UpdateParameters>
</asp:AccessDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="username" DataSourceID="AccessDataSource1" AllowPaging="True" CellPadding="10" ForeColor="#333333" GridLines="None" AllowSorting="True" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True">
<AlternatingRowStyle BackColor="White" ForeColor="#284775"></AlternatingRowStyle>
<Columns>
<asp:BoundField DataField="username" HeaderText="username" SortExpression="username" ItemStyle-HorizontalAlign="Center"></asp:BoundField>
<asp:BoundField DataField="password" HeaderText="password" SortExpression="password"></asp:BoundField>
<asp:BoundField DataField="isAdmin" HeaderText="isAdmin" SortExpression="isAdmin"></asp:BoundField>
</Columns>
<EditRowStyle BackColor="#999999"></EditRowStyle>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"></FooterStyle>
<HeaderStyle Font-Bold="True" ForeColor="#cecece"></HeaderStyle>
<PagerStyle HorizontalAlign="Center" BackColor="#284775" ForeColor="#284775"></PagerStyle>
<RowStyle BackColor="#f8f8f9" ForeColor="#fff"></RowStyle>
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333"></SelectedRowStyle>
</asp:GridView>
Related
<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've worked on this for a while and realized that my DetailsView actually works fine by itself (I tested it on another page).
But when I put it in the tab layout of the page, and click Edit, it clears all values in the database with null values on updating.
For example here's the page: http://pactlegacy.com/sentinel/employeeprofile.aspx?curEmp=3
Here's the DetailsView:
<div id="tab-general" class="tabs-content">
<div class="avatar">
<h3>General Information</h3>
</div>
<fieldset class="grey-bg">
<legend>Required fields</legend>
<div class="colx3-left-double">
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px"
AutoGenerateRows="False" DataKeyNames="ID" DataSourceID="SqlDataSource1">
<Fields>
<asp:CommandField ShowEditButton="True" ButtonType="Button"/>
<asp:BoundField DataField="FirstName" HeaderText="First Name"
SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="Last Name"
SortExpression="LastName" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="JobID" HeaderText="JobID" SortExpression="JobID" />
<asp:BoundField DataField="SupervisorID" HeaderText="SupervisorID"
SortExpression="SupervisorID" />
<asp:BoundField DataField="HireDate" HeaderText="Hire Date"
SortExpression="HireDate" />
<asp:BoundField DataField="Status" HeaderText="Status"
SortExpression="Status" />
<asp:CommandField ShowEditButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:dbConnectionString %>"
DeleteCommand="DELETE FROM [Users] WHERE [ID] = #ID"
InsertCommand="INSERT INTO [Users] ([ClientID], [UserName], [Password], [FirstName], [LastName], [Email], [JobID], [SupervisorID], [HireDate], [Status]) VALUES (#ClientID, #UserName, #Password, #FirstName, #LastName, #Email, #JobID, #SupervisorID, #HireDate, #Status)"
ProviderName="<%$ ConnectionStrings:dbConnectionString.ProviderName %>"
SelectCommand="SELECT [ID], [ClientID], [UserName], [Password], [FirstName], [LastName], [Email], [JobID], [SupervisorID], [HireDate], [Status] FROM [Users] WHERE [ID] = #ID"
UpdateCommand="UPDATE [Users] SET [ClientID] = #ClientID, [UserName] = #UserName, [Password] = #Password, [FirstName] = #FirstName, [LastName] = #LastName, [Email] = #Email, [JobID] = #JobID, [SupervisorID] = #SupervisorID, [HireDate] = #HireDate, [Status] = #Status WHERE [ID] = #ID">
<SelectParameters>
<asp:QueryStringParameter Name="ID" QueryStringField="curEmp" Type="Int64" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="ClientID" Type="Int64" />
<asp:Parameter Name="UserName" Type="String" />
<asp:Parameter Name="Password" Type="String" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="JobID" Type="Double" />
<asp:Parameter Name="SupervisorID" Type="Double" />
<asp:Parameter Name="HireDate" Type="DateTime" />
<asp:Parameter Name="Status" Type="String" />
<asp:Parameter Name="ID" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
</fieldset>
</div>
Does anyone know why this is happening? What do I need to change have my DetailsView update properly within my tab layout?
You need to add an ID field in the DetailsView like below:
<asp:BoundField
DataField="ID"
HeaderText="ID"
InsertVisible="False"
ReadOnly="True"
SortExpression="ID" />
This is the primary key you are missing in DetailsView.
I have a problem about the updating a column of my gridview; when I try to update the field I get this error:
Incorrect syntax near 'nvarchar'.
Must declare the scalar variable "#pid".
Here is a piece of my code:
<asp:GridView ID="GridView1" runat="server" name="gd" Height="100px"
Width="435px" AutoGenerateColumns="False" DataKeyNames="pid" DataSourceID="SqlDataSource1" >
<Columns>
<asp:CommandField ShowEditButton="True" ShowSelectButton="True" />
<asp:BoundField DataField="pid" HeaderText="pid"
SortExpression="pid" ReadOnly="True" />
<asp:BoundField DataField="name" HeaderText="name"
SortExpression="name" />
<asp:BoundField DataField="hoghoghe rozane" HeaderText="hoghoghe rozane"
SortExpression="hoghoghe rozane" />
<asp:BoundField DataField="paye" HeaderText="paye"
SortExpression="paye" />
<\Columns>
<asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
UpdateCommand="UPDATE [post] SET [name] = #name, hoghoghe_rozane = #hoghoghe_rozane, [paye] = #paye WHERE (pid = #pid)" >
<UpdateParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="hoghoghe_rozane" Type="Int32" />
<asp:Parameter Name="paye" Type="Int32" />
<asp:Parameter Name="pid" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
chek this out : same problem
it says you must change [hoghoghe rozane] into [hoghoghe_rozane]
Update :::
1.Make sure that the type of pid field in database
2.fields should not have spaces in your tables
3.alias should not have spaces too
try this code :
<asp:GridView ID="GridView1" runat="server" name="gd" Height="100px"
Width="435px" AutoGenerateColumns="False" DataKeyNames="pid" DataSourceID="SqlDataSource1" >
<Columns>
<asp:CommandField ShowEditButton="True" ShowSelectButton="True" />
<asp:BoundField DataField="pid" HeaderText="pid"
SortExpression="pid" ReadOnly="True" />
<asp:BoundField DataField="name" HeaderText="name"
SortExpression="name" />
<asp:BoundField DataField="hoghoghe_rozane" HeaderText="hoghogheRozane"
SortExpression="hoghoghe_rozane" />
<asp:BoundField DataField="paye" HeaderText="paye"
SortExpression="paye" />
<\Columns>
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
UpdateCommand="UPDATE [post] SET [name] = #name, hoghoghe_rozane = #hoghoghe_rozane, [paye] = #paye WHERE (pid = #pid)" >
<UpdateParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="hoghoghe_rozane" Type="Int32" />
<asp:Parameter Name="paye" Type="Int32" />
<asp:Parameter Name="pid" Type="String" />
</UpdateParameters>
hope that would work.
Please forgive my ignorance. I have a done a bit of web programming but am new to ASP.NET and find it mystifying when trying to do something not out of the box.
I have a GridView that gets its data from a SQL Server view. I have a DetailsView that needs to manipulate data in a table. I cannot figure out how to link the GridView to the DetailsView correctly.
Below is the code for the section of the aspx page that contains the GridView and DetailsView. The latest error in an endless procession of errors is: Must declare the scalar variable "#ID".
I would appreciate any help that anyone can offer. Thanks.
<asp:GridView ID="gvVendorContacts" runat="server" AutoGenerateColumns="False"
DataSourceID="dsApplications_Contacts" AllowSorting="True" CellPadding="4" CellSpacing="2" AutoGenerateSelectButton="True" DataKeyNames="ContactID"
onselectedindexchanged="gvVendorContacts_SelectedIndexChanged">
<AlternatingRowStyle BackColor="#E8F3FF" />
<Columns>
<asp:BoundField DataField="FullName" HeaderText="Name" ReadOnly="True"
SortExpression="FullName" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="Role" HeaderText="Role" SortExpression="Role" />
<asp:BoundField DataField="Office Phone" HeaderText="Office Phone"
SortExpression="Office Phone" />
<asp:BoundField DataField="Mobile Phone" HeaderText="Mobile Phone"
SortExpression="Mobile Phone" />
<asp:TemplateField HeaderText="Email" SortExpression="Email">
<ItemTemplate>
<%#Eval("Email")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="dsApplications_Contacts" runat="server"
ConnectionString="<%$ ConnectionStrings:MDSConnectionString %>"
SelectCommand="SELECT [ApplicationID], [ContactID], [FName], [LName], [FullName], [Title], [Role], [OfficePhone] As [Office Phone], [MobilePhone] As [Mobile Phone], [Email] FROM [vw_Applications_Contacts] WHERE ApplicationName = 'Bloomberg'">
</asp:SqlDataSource>
<asp:DetailsView ID="dvVendorContacts" runat="server" AutoGenerateRows="False"
DataKeyNames="ID" DataSourceID="dsVendorContacts" Height="100px"
Width="200px" BackColor="White" BorderColor="#CC9966" BorderStyle="None"
BorderWidth="1px" CellPadding="4">
<EditRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<Fields>
<asp:BoundField DataField="ContactID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="FName" HeaderText="FName" SortExpression="FName" />
<asp:BoundField DataField="LName" HeaderText="LName" SortExpression="LName" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="Role" HeaderText="Role" SortExpression="Role" />
<asp:BoundField DataField="OfficePhone" HeaderText="OfficePhone"
SortExpression="OfficePhone" />
<asp:BoundField DataField="MobilePhone" HeaderText="MobilePhone"
SortExpression="MobilePhone" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
</Fields>
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<RowStyle BackColor="White" ForeColor="#330099" />
</asp:DetailsView>
<asp:SqlDataSource ID="dsVendorContacts" runat="server"
ConnectionString="<%$ ConnectionStrings:MDSConnectionString %>"
DeleteCommand="DELETE FROM [Contacts] WHERE [ID] = #ID"
InsertCommand="INSERT INTO [Contacts] ([FName], [LName], [Title], [Role], [OfficePhone], [MobilePhone], [Email]) VALUES (#FName, #LName, #Title, #Role, #OfficePhone, #MobilePhone, #Email)"
SelectCommand="SELECT [ID], [FName], [LName], [Title], [Role], [OfficePhone], [MobilePhone], [Email] FROM [Contacts] WHERE ([ID] = #ID)"
UpdateCommand="UPDATE [Contacts] SET [FName] = #FName, [LName] = #LName, [Title] = #Title, [Role] = #Role, [OfficePhone] = #OfficePhone, [MobilePhone] = #MobilePhone, [Email] = #Email WHERE [ID] = #ID">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="FName" Type="String" />
<asp:Parameter Name="LName" Type="String" />
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Role" Type="String" />
<asp:Parameter Name="OfficePhone" Type="String" />
<asp:Parameter Name="MobilePhone" Type="String" />
<asp:Parameter Name="Email" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="FName" Type="String" />
<asp:Parameter Name="LName" Type="String" />
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Role" Type="String" />
<asp:Parameter Name="OfficePhone" Type="String" />
<asp:Parameter Name="MobilePhone" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="gvVendorContacts" DefaultValue="NULL"
Name="ContactID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
Looks like your select statement is expecting #ID but your SelectParameter is ContactId.
I have grid view with folowing complete code With Msaccess DB.I have used the decode function in sql query.When i press the edit button on grid view it shows folowing error
"DropDownList2' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value"
My SQL Data source code is below
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DataConnectionString2 %>"
DeleteCommand="DELETE FROM [EMAILS] WHERE [ID] = ?" InsertCommand="INSERT INTO [EMAILS] ([Email], [FULLNAME],[FLAG]) VALUES (?, ?, ?)"
ProviderName="<%$ ConnectionStrings:DataConnectionString2.ProviderName %>" SelectCommand="SELECT ID, Email, FULLNAME, switch(FLAG = 1, 'Allowed', Flag = 0, 'Not Allowed') AS FLAG FROM EMAILS"
UpdateCommand="UPDATE [EMAILS] SET [Email] = ?, [FULLNAME] = ?,[FLAG] = ? WHERE [ID] = ?">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="FULLNAME" Type="String" />
<asp:Parameter Name="FLAG" Type="Int32" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="FULLNAME" Type="String" />
<asp:Parameter Name="FLAG" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
And Grid View Code is bellow
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" BackColor="White" BorderColor="#CC9966" BorderStyle="None"
BorderWidth="1px" CellPadding="4" DataKeyNames="ID" DataSourceID="SqlDataSource1"
HorizontalAlign="Center" Width="821px" EmptyDataText="No Emails Found">
<RowStyle BackColor="White" Font-Names="Arial" Font-Size="Small" ForeColor="Black" />
<Columns>
<asp:CommandField ButtonType="Button" ShowEditButton="True" ShowSelectButton="True" ShowDeleteButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
SortExpression="ID" Visible="False" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="FULLNAME" HeaderText="Full Name" SortExpression="FULLNAME" />
<asp:TemplateField HeaderText="Flag" SortExpression="FLAG">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" SelectedValue="<%# Bind('FLAG') %>" AppendDataBoundItems="True">
<asp:ListItem Value="1">Allowed</asp:ListItem>
<asp:ListItem Value="0">Not Allowed</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("FLAG") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<HeaderStyle BackColor="#990000" Font-Bold="True" Font-Names="Arial" Font-Size="Small"
ForeColor="#FFFFCC" HorizontalAlign="Center" />
<EmptyDataRowStyle BackColor="#804000" Font-Names="Arial" Font-Size="Small" ForeColor="White" />
</asp:GridView>
Please tell me what possible error is here
Check weather the value in Field flag of the row you are trying to edit, is available in the DropDownList in EditItemTemplate
And try removing AppendDataBoundItems="True" in DropDownList in EditItemTemplate