Solved

sql update via gridview

Posted on 2008-10-30
5
263 Views
Last Modified: 2013-12-17
I have a gridview which I am updating using code.

I have ran into a mess with the update as data is not beign added to the correct columns.

On SQL 2005 my stored procedure works fine, but when I execute the code to input the details things just don't match.
0
Comment
Question by:Mr_Shaw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22847645
check the binding of grid ... also check in code whether you are passing correct data to update ... one more thing .. did you gridview contain datakesyname .... if not set it first
also paste your code here ...
0
 

Author Comment

by:Mr_Shaw
ID: 22848529
my code is:

my code is

protected void edit_record_updating(object sender, GridViewUpdateEventArgs e)
    {
       
        update_class update_records_method = new update_class();
        update_records_method.Record_ID = ((TextBox)user_records.Rows[e.RowIndex].Cells[2].Controls[0]).Text.ToString();
        update_records_method.Logon_Name = WindowsIdentity.GetCurrent().Name.ToString();
        update_records_method.Record_Class = ((TextBox)user_records.Rows[e.RowIndex].Cells[4].Controls[0]).Text.ToString();  
        update_records_method.Record_Name = ((TextBox)user_records.Rows[e.RowIndex].Cells[6].Controls[0]).Text.ToString();
}

I did not use andy datakeyname as I am not sure how to use this property.
0
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22848722
in your case its not require (datakeys)
are you getting this record correct
 update_records_method.Record_ID = ((TextBox)user_records.Rows[e.RowIndex].Cells[2].Controls[0]).Text.ToString();

also what problem you are getting in update ...

0
 

Author Comment

by:Mr_Shaw
ID: 22848768
I have tested my code using break points and I have concluded that the following;

When I click the Edit button on the gridview TextBoxes appear to allow me to edit the content.
When I click the Update button the code does not recognise that the TextBoxes have been updated and no change is made.

I have tested the code with other virables which works successfully (i.e new values are inserted and appear in the gridview). There is something wrong with the way i am picking up the editted values from the gridview.

0
 
LVL 16

Accepted Solution

by:
Gyanendra Singh earned 500 total points
ID: 22852596
try this

set Datakeysname to your grid
<asp:GridView ID="GridView1" runat="server" DataSourceID="yrdatasource"
DataKeyNames="Record_ID"

     protected void GridView1_RowUpdating(object sender, System.Web.UI.WebControls.GridViewUpdateEventArgs e)
     {
       
         String Record_ID= GridView1.DataKeys(e.RowIndex).Value.ToString();
       
         System.Web.UI.WebControls.TextBox Name = new System.Web.UI.WebControls.TextBox();
         Name = (TextBox)this.GridView1.Rows(e.RowIndex).Cells(cellnumber).Controls(0);
         string vName = Name.Text;

        // Your update query
       
       
         GridView1.EditIndex = -1;
         BindGrid();
     }

0

Featured Post

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Connect Gridview column to Textbox in C# 2 52
Telerik RadEditor Control Save 8 36
SQL Server Serialization error 8 41
How do I "share" on social sites? 2 32
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

736 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question