-
September 12th, 2014, 06:18 AM
#1
GridView UpdateCommand SQL
First time trying to set up GridView on ASP.NET:
Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="gvDepartments" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="id,dept_name,dept_abbr" DataSourceID="DBDeptInfoSource" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" OnSelectedIndexChanged="gvDepartments_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="id" HeaderText="#" SortExpression="id" ReadOnly="true" />
<asp:BoundField DataField="dept_name" HeaderText="Dept. Name" SortExpression="dept_name" ReadOnly="false" />
<asp:BoundField DataField="dept_abbr" HeaderText="Dept. Abbr" SortExpression="dept_abbr" ReadOnly="false" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="DBDeptInfoSource" runat="server" ConnectionString="<%$ ConnectionStrings:DBDeptInfo %>" EnableViewState="False"
SelectCommand="SELECT id,dept_name,dept_abbr FROM Departments"
UpdateCommand="UPDATE Departments SET dept_name=@dept_name,dept_abbr=@dept_abbr WHERE id=@id"
DeleteCommand="DELETE FROM Departments WHERE id=@id"
>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
The SelectCommand and DeleteCommand params work, but UpdateCommand does not.
- I know I have access to write to the database, as DeleteCommand works.
- I read somewhere that it could just be that the GridView wasn't refreshing after postback, but that it was updating the database record. I have verified that the data is NOT being updated in the database.
Help me learn!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|