Click here to Skip to main content
15,887,936 members
Home / Discussions / C#
   

C#

 
GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell10-May-15 21:07
Norris Chappell10-May-15 21:07 
GeneralRe: Update in C# using SQL Server Database. Pin
Agent__00710-May-15 22:12
professionalAgent__00710-May-15 22:12 
GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell11-May-15 5:49
Norris Chappell11-May-15 5:49 
GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell11-May-15 6:54
Norris Chappell11-May-15 6:54 
GeneralRe: Update in C# using SQL Server Database. Pin
Mycroft Holmes11-May-15 14:43
professionalMycroft Holmes11-May-15 14:43 
GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell11-May-15 15:22
Norris Chappell11-May-15 15:22 
GeneralRe: Update in C# using SQL Server Database. Pin
Mycroft Holmes11-May-15 16:09
professionalMycroft Holmes11-May-15 16:09 
AnswerRe: Update in C# using SQL Server Database. Pin
Agent__00711-May-15 17:20
professionalAgent__00711-May-15 17:20 
Norris Chappell wrote:
cmd.Parameters.AddWithValue("@Name", Convert.ToString(gvKeyPersonnel.DataKeys[row.RowIndex].Values[1]));
This statement shouldn't be there, you should only have your "ID" field in the DataKeys. Instead, you should be having something like this:
C#
cmd.Parameters.AddWithValue("@Name", row.Cells[IndexOfCellContainingNameField].Text); // Note that, I am assuming you are not having any template for your "Name" field, like a label, in which case you need to use FindControl() method on your cell and then use .Text on that label
Regarding the IndexOutOfRangeException you are getting, I think if you only have the "ID" in the DataKeys property (i.e. remove the "Name" from DataKeys and pass its value like the above line), that won't come up - assuming your RowIndex is not the culprit.

Not related to your current question, but I think if you are having to iterate all rows in the grid for updating a row, you might want to have a look at examples here[^], here[^] or here[^].
You have just been Sharapova'd.

GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell11-May-15 20:09
Norris Chappell11-May-15 20:09 
GeneralRe: Update in C# using SQL Server Database. Pin
Agent__00711-May-15 20:30
professionalAgent__00711-May-15 20:30 
GeneralRe: Update in C# using SQL Server Database. Pin
Mycroft Holmes11-May-15 22:32
professionalMycroft Holmes11-May-15 22:32 
GeneralRe: Update in C# using SQL Server Database. Pin
Pete O'Hanlon12-May-15 0:26
mvePete O'Hanlon12-May-15 0:26 
GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell12-May-15 4:27
Norris Chappell12-May-15 4:27 
GeneralRe: Update in C# using SQL Server Database. Pin
Pete O'Hanlon12-May-15 4:49
mvePete O'Hanlon12-May-15 4:49 
GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell12-May-15 11:36
Norris Chappell12-May-15 11:36 
GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell12-May-15 11:55
Norris Chappell12-May-15 11:55 
GeneralRe: Update in C# using SQL Server Database. Pin
Pete O'Hanlon12-May-15 13:45
mvePete O'Hanlon12-May-15 13:45 
GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell12-May-15 13:51
Norris Chappell12-May-15 13:51 
GeneralRe: Update in C# using SQL Server Database. Pin
Pete O'Hanlon12-May-15 19:57
mvePete O'Hanlon12-May-15 19:57 
GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell12-May-15 20:02
Norris Chappell12-May-15 20:02 
GeneralRe: Update in C# using SQL Server Database. Pin
Pete O'Hanlon12-May-15 21:00
mvePete O'Hanlon12-May-15 21:00 
GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell12-May-15 21:55
Norris Chappell12-May-15 21:55 
GeneralRe: Update in C# using SQL Server Database. Pin
Pete O'Hanlon12-May-15 22:17
mvePete O'Hanlon12-May-15 22:17 
GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell13-May-15 3:48
Norris Chappell13-May-15 3:48 
GeneralRe: Update in C# using SQL Server Database. Pin
Pete O'Hanlon13-May-15 4:11
mvePete O'Hanlon13-May-15 4:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.