GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Microsoft  >  Ado.NET
Go To First  |  Previous Question  |  Next Question 
 Ado.NET  |  Question 28 of 31    Print  
How to update a column in DataGrid using C#
I am getting InvalidCastException as (Specified cast is not valid) while updating 2nd column in a datagrid? Id,firstname,lastname are the three columns of my datagrid respectively. I wanted to edit the second column(lastname) and update it. I did the following code in DataGrid's updatecommand(),but failed to update !
Int varid=(int)DataGrid1.DataKeys[e.Item.ItemIndex]; TextBox lnm=(TextBox)e.Item.Cells[2].Controls[0]; string str=lnm.Text ; SqlCommand cmd=new SqlCommand("update customer set lastname='" + str + "' where id=" + varid + "",con); cmd.ExecuteNonQuery(); DataGrid1.EditItemIndex=-1; DataGrid1.DataBind();



  
Total Answers and Comments: 2 Last Update: July 10, 2008     Asked by: pen2satya 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
November 01, 2007 09:58:44   #1  
santosh.net.india        

RE: How to update a column in DataGrid using C#
 Did u not set the data key property of datagrid,pl set key in data key feild
 
Is this answer useful? Yes | No
July 10, 2008 09:16:19   #2  
sureshnaspuri Member Since: July 2008   Contribution: 2    

RE: How to update a column in DataGrid using C#
After seeing ur code i understood that u haven't call the bind method.

gridview1.EditItemIndex = -1;
after this u call the bind method .

gridview1.databind();//in this place u call the grid bind method n try it once.


 
Is this answer useful? Yes | No

 Related Questions

Latest Answer : We will update the dataset by calling Update Method.We will update the database by calling AcceptChanges Method. ...

I am getting InvalidCastException as (Specified cast is not valid) while updating 2nd column in a datagrid? Id,firstname,lastname are the three columns of my datagrid respectively. I wanted to edit the 
Latest Answer : After seeing ur code i understood that u haven't call the bind method.gridview1.EditItemIndex = -1;after this u call the bind method .gridview1.databind();//in this place u call the grid bind method n try it once. ...


 Sponsored Links

 
Related Articles

jQuery - Column Highlighting

Learning jQuery Column Highlighting It can be a nice user interface enhancement to visually remind the user of what has been done in the past By highlighting the column that was most recently used for sorting we can focus the user s attention on the part of the table that is most likely to be releva
 

The Interview Snafu

How to turn someone else’s mistake to your advantage Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
 

Winning a Job Interview with a Winning Resume

Does your resume unlock your potential, take your skills to the highest level and win you the interview and the job you want now? The job market today is highly competitive and even if you think you have what it takes to get an interview you won’t get over the line without a polished, prof
 

Importance of Proper English during Job Interview

Importance of Proper English during Job Interview Your job interview is crucially important and it will determine whether or not you will get the job Depending on the type of job you re going for it is very important for you to use proper English In most cases jobs which offer higher salaries will h
 

CSS3 Multi Column Feature

CSS3 Multi Column Feature CSS3 Multi Column Module is a vital feature present in CSS3 This feature enables users to flow the content of an element into multiple columns The CSS3 Multi Column Module is a important feature because it gives users the following features or advantages there is no need to
 

HR Interview - HR Interview Mistakes You Will Want To Avoid

HR Interview Mistakes You Will Want To Avoid The job interview can be a stressful process This is especially true for those who are going after a competitive position Your nonverbal communication combined with the answers you give during the interview will determine if you are hired mosgoogle While
 

HR Interview - Behavioral HR Interviews

Behavioral HR Interviews As the name implies a behavioral interview is an interview that is held by a human resources department to determine if an applicant has the behaviors that are appropriate for a job The company must know how an applicant will behave in a certain situations mosgoogle The logi
 

HR Interview - How To Prepare For Your HR Interview

How To Prepare For Your HR Interview Before you begin thinking about how you are going to dress for the interview it is important to do your research first You should learn everything you can about the company you wish to work for When you have detailed information about your employer you will conve
 

HR Interview - Telephone Interview Etiquette

Telephone Interview Etiquette When you conduct a telephone interview for a job it is important to show the proper etiquette Not only is it important it is critical is you wish to be hired by the company There are a number of things you will want to do and other things should never be done mosgoogle
 

HR Interview - How To Succeed At HR Interviews

How To Succeed At HR Interviews There are a number of things you will need to do in order to make sure you pass the interview process Your appearance is something that you will want to pay close attention to Even if you feel that your appearance shouldn t be a factor in whether or not you re highere
 





About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape