Jump to content
xisto Community
Sign in to follow this  
dhanesh1405241511

[help] Gridview In Asp Not Updating Values

Recommended Posts

Sorry i am just repeating a question that has been asked a million times, but every answer seems to be either too advanced or not satisfying. I have a simple gridview .. and it shows all the values in the table its connected too .. but when i edit or delete .. the values in the table do not get updated .. Here is my code .. hope you guys can help me ..

 

[b]1	[/b]<%@ Page Language="VB" %>[b]2	[/b]<%@ Import Namespace="System.Data" %>[b]3	[/b]<%@ Import Namespace="System.Data.OleDb" %>[b]4	[/b]<script language="VB" runat="server">[b]5	[/b]	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)[b]6	[/b]		Dim myConnection As New OleDbConnection[b]7	[/b]		myConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " _[b]8	[/b]		 & "Data Source=" & Server.MapPath("App_Data\origin_ts.mdb") & ";")[b]9	[/b]		Dim myCommand As New OleDbCommand[b]10   [/b]		myCommand.Connection = myConnection[b]11   [/b]		myCommand.CommandText = "SELECT * FROM TimeSheet"[b]12   [/b]		myCommand.CommandType = CommandType.Text[b]13   [/b]		Dim myda As New OleDbDataAdapter[b]14   [/b]		myda.SelectCommand = myCommand[b]15   [/b]		Dim mydg As New GridView[b]16   [/b]		'Me.GridView1.DataBind()[b]17   [/b]		Dim dss As New AccessDataSource[b]18   [/b]		dss.DataBind()[b]19   [/b]		Dim myds As New DataSet[b]20   [/b]		myda.Fill(myds, "TimeSheet")[b]21   [/b][b]22   [/b]	End Sub[b]23   [/b][b]24   [/b]	Protected Sub btlogout_Click(ByVal sender As Object, ByVal e As System.EventArgs)[b]25   [/b]		FormsAuthentication.SignOut()[b]26   [/b]		Response.Redirect("login.aspx")[b]27   [/b]	End Sub[b]28   [/b][b]29   [/b]</script>

This is my Script code ...

 

Now here is my html code for the gridview:

 

[b]1	[/b]  <asp:AccessDataSource ID="AccessDataSource1" runat="server" ConflictDetection="CompareAllValues"[b]2	[/b]								DataFile="~/App_Data/origin_ts.mdb" DeleteCommand="DELETE FROM [TimeSheet] WHERE [TimeSheetID] = ? AND [Day_Date] = ? AND [UserName] = ? AND [Client Name] = ? AND [Job Description] = ? AND [Job Type] = ? AND [Hours] = ?"[b]3	[/b]								InsertCommand="INSERT INTO [TimeSheet] ([TimeSheetID], [Day_Date], [UserName], [Client Name], [Job Description], [Job Type], [Hours]) VALUES (?, ?, ?, ?, ?, ?, ?)"[b]4	[/b]								OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [TimeSheet] WHERE ([UserName] = ?)"[b]5	[/b]								UpdateCommand="UPDATE [TimeSheet] SET [Day_Date] = ?, [UserName] = ?, [Client Name] = ?, [Job Description] = ?, [Job Type] = ?, [Hours] = ? WHERE [TimeSheetID] = ? AND [Day_Date] = ? AND [UserName] = ? AND [Client Name] = ? AND [Job Description] = ? AND [Job Type] = ? AND [Hours] = ?">[b]6	[/b]								<DeleteParameters>[b]7	[/b]									<asp:Parameter Name="original_TimeSheetID" Type="Int32" />[b]8	[/b]									<asp:Parameter Name="original_Day_Date" Type="DateTime" />[b]9	[/b]									<asp:Parameter Name="original_UserName" Type="String" />[b]10   [/b]									<asp:Parameter Name="original_Client_Name" Type="String" />[b]11   [/b]									<asp:Parameter Name="original_Job_Description" Type="String" />[b]12   [/b]									<asp:Parameter Name="original_Job_Type" Type="String" />[b]13   [/b]									<asp:Parameter Name="original_Hours" Type="Int32" />[b]14   [/b]								</DeleteParameters>[b]15   [/b]								<UpdateParameters>[b]16   [/b]									<asp:Parameter Name="Day_Date" Type="DateTime" />[b]17   [/b]									<asp:Parameter Name="UserName" Type="String" />[b]18   [/b]									<asp:Parameter Name="Client_Name" Type="String" />[b]19   [/b]									<asp:Parameter Name="Job_Description" Type="String" />[b]20   [/b]									<asp:Parameter Name="Job_Type" Type="String" />[b]21   [/b]									<asp:Parameter Name="Hours" Type="Int32" />[b]22   [/b]									<asp:Parameter Name="original_TimeSheetID" Type="Int32" />[b]23   [/b]									<asp:Parameter Name="original_Day_Date" Type="DateTime" />[b]24   [/b]									<asp:Parameter Name="original_UserName" Type="String" />[b]25   [/b]									<asp:Parameter Name="original_Client_Name" Type="String" />[b]26   [/b]									<asp:Parameter Name="original_Job_Description" Type="String" />[b]27   [/b]									<asp:Parameter Name="original_Job_Type" Type="String" />[b]28   [/b]									<asp:Parameter Name="original_Hours" Type="Int32" />[b]29   [/b]								</UpdateParameters>[b]30   [/b]								<SelectParameters>[b]31   [/b]									<asp:SessionParameter Name="UserName" SessionField="S2" Type="String" />[b]32   [/b]								</SelectParameters>[b]33   [/b]								<InsertParameters>[b]34   [/b]									<asp:Parameter Name="TimeSheetID" Type="Int32" />[b]35   [/b]									<asp:Parameter Name="Day_Date" Type="DateTime" />[b]36   [/b]									<asp:Parameter Name="UserName" Type="String" />[b]37   [/b]									<asp:Parameter Name="Client_Name" Type="String" />[b]38   [/b]									<asp:Parameter Name="Job_Description" Type="String" />[b]39   [/b]									<asp:Parameter Name="Job_Type" Type="String" />[b]40   [/b]									<asp:Parameter Name="Hours" Type="Int32" />[b]41   [/b]								</InsertParameters>[b]42   [/b]							</asp:AccessDataSource>[b]43   [/b]							<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"[b]44   [/b]								AutoGenerateColumns="False" DataKeyNames="TimeSheetID" DataSourceID="AccessDataSource1" BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None">[b]45   [/b]								<Columns>[b]46   [/b]									<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />[b]47   [/b]									<asp:BoundField DataField="TimeSheetID" HeaderText="TimeSheetID" InsertVisible="False"[b]48   [/b]										ReadOnly="True" SortExpression="TimeSheetID" />[b]49   [/b]									<asp:BoundField DataField="Day_Date" HeaderText="Day_Date" SortExpression="Day_Date" />[b]50   [/b]									<asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" />[b]51   [/b]									<asp:BoundField DataField="Client Name" HeaderText="Client Name" SortExpression="Client Name" />[b]52   [/b]									<asp:BoundField DataField="Job Description" HeaderText="Job Description" SortExpression="Job Description" />[b]53   [/b]									<asp:BoundField DataField="Job Type" HeaderText="Job Type" SortExpression="Job Type" />[b]54   [/b]									<asp:BoundField DataField="Hours" HeaderText="Hours" SortExpression="Hours" />[b]55   [/b]								</Columns>[b]56   [/b]								<FooterStyle BackColor="Tan" />[b]57   [/b]								<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />[b]58   [/b]								<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />[b]59   [/b]								<HeaderStyle BackColor="Tan" Font-Bold="True" />[b]60   [/b]								<AlternatingRowStyle BackColor="PaleGoldenrod" />[b]61   [/b]							</asp:GridView>

I cant find anything wrong here, so how can i manually update this or delete a value .. or please suggest any other alternative ?

 

TimeSheet Table has the Following:

TimeSheetID --> This is the Primary Key

Day_Date

UserName

Client Name

Job Description

Job Types

Hours

And the Column names are exactly as in my table, I hope the capital and spaces don't make a difference. Should i be changing the primary key to something else ? Like Day_Date ? Cause UserName is Primary key of User table and Client Name is primary key of Client table. So basically its just 3 tables and its pretty simple, but i have no clue where i am going wrong.

 

Thanks in Advance .. Regards

Edited by dhanesh (see edit history)

Share this post


Link to post
Share on other sites
GridView1_RowUpdating not taking updated values in c#[help] Gridview In Asp Not Updating Values

am updating gridview using c# ... Below is my code..

please give me the solution..Thanks in advance

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)

{

SqlConnection con = new SqlConnection(constring1);

con.Open();

TextBox rol = new TextBox();

TextBox name = new TextBox();

TextBox phone = new TextBox();

rol.Text=((TextBox)GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).Text;

name.Text=((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;

phone.Text =((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text;

String str = " update student set Name='"+name.Text+"',Phone='"+phone.Text+"' where Roll='"+rol.Text+"'";

SqlCommand cmd = new SqlCommand(str, con);

cmd.ExecuteNonQuery();

con.Close();

}

-reply by naryan

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.