Click here to Skip to main content
15,907,326 members
Home / Discussions / C#
   

C#

 
GeneralVS 's Installer Pin
zecodela15-Mar-05 15:21
zecodela15-Mar-05 15:21 
GeneralRe: VS 's Installer Pin
Dave Kreskowiak16-Mar-05 14:37
mveDave Kreskowiak16-Mar-05 14:37 
GeneralGDI GradientFill Pin
Mathew Hall15-Mar-05 14:33
Mathew Hall15-Mar-05 14:33 
GeneralRe: GDI GradientFill Pin
Christian Graus15-Mar-05 14:52
protectorChristian Graus15-Mar-05 14:52 
GeneralRe: GDI GradientFill Pin
Mathew Hall15-Mar-05 17:10
Mathew Hall15-Mar-05 17:10 
Generali want to know something Pin
snouto15-Mar-05 12:32
snouto15-Mar-05 12:32 
GeneralRe: i want to know something Pin
Christian Graus15-Mar-05 12:57
protectorChristian Graus15-Mar-05 12:57 
GeneralUsing the update command of the datagrid to alter the data in a dataset Pin
Anonymous15-Mar-05 12:18
Anonymous15-Mar-05 12:18 
I have managed to get succesfully working the , delete and cancel functions working within the datagrid to alter data held in dataset that then updates a SQL Database.

When I click edit the correct row changes into textboxes to make the changes. Then when I click update is when I get stuck. I am using the datagrid (dgCustomers) items index and DataKeyField (CustomerID) to search for the correct row within the dataset, to update.

here is the code:

private void dgCustomers_UpdateCommand(object source, system.Web.UI.WebControls.DataGridCommandEventArgs e)


{
// //Test Label to see the value of the datakey is correct
Label6.Text = dgCustomers.DataKeys[e.Item.ItemIndex].ToString();

//Select correct row using the index and datakeyfield.
DataRow[] adrEdit = ds.Tables["Customers"].Select("CustomerID = 'dgCustomers.DataKeys[e.Items.ItemIndex]'");

//Make sure there is data
if(adrEdit.Length > 0)
{
//Put in the edited data
TextBox txtCompanyName = (TextBox) e.Item.Cells[3].Controls[0];
adrEdit[0]["CompanyName"] = txtCompanyName.Text;
TextBox txtContactName = (TextBox) e.Item.Cells[4].Controls[0];
adrEdit[0]["ContactName"] = txtContactName.Text;
}
else
{
LblResult.Text = "Not Updated";
}
//End editing
dgCustomers.EditItemIndex = -1;
//Update the database
da.Update(ds,"Customers");
//And bind data to the ui
LoadData();
}

For some reason it doesn't find the necessary data and skips the if loop. The test label(label6) however does return the value of a customerID suck as ALFKI.

If I replace this row

DataRow[] adrEdit = ds.Tables["Customers"].Select("CustomerID = 'dgCustomers.DataKeys[e.Items.ItemIndex]'")

With this more explicit statement

DataRow[] adrEdit = ds.Tables["Customers"].Select("CustomerID = 'ALFKI'")

It actually works, but obviously updates only the ALFKI row. Can anyone shed any light on where I may be going wrong, or is it just my comp playing funny buggers with me again!

Many thanks

Paul Custance
GeneralReceiving SMS problem Pin
ccui15-Mar-05 10:18
ccui15-Mar-05 10:18 
GeneralDataGrid TableStyles Pin
dennista15-Mar-05 9:03
dennista15-Mar-05 9:03 
GeneralRe: DataGrid TableStyles Pin
Kodanda Pani15-Mar-05 18:06
Kodanda Pani15-Mar-05 18:06 
GeneralRe: DataGrid TableStyles Pin
dennista16-Mar-05 3:31
dennista16-Mar-05 3:31 
GeneralFile IO in Webservice gives Error Pin
James Poulose15-Mar-05 8:21
James Poulose15-Mar-05 8:21 
GeneralRe: File IO in Webservice gives Error Pin
TylerBrinks15-Mar-05 9:46
TylerBrinks15-Mar-05 9:46 
QuestionHow to create a shallow copy of List<T> ? Pin
Andres Coder15-Mar-05 7:50
Andres Coder15-Mar-05 7:50 
AnswerRe: How to create a shallow copy of List<T> ? Pin
leppie15-Mar-05 8:51
leppie15-Mar-05 8:51 
GeneralSending a web form as parameter Pin
see0715-Mar-05 7:45
see0715-Mar-05 7:45 
GeneralRe: Sending a web form as parameter Pin
Pushkar Pathak15-Mar-05 18:16
Pushkar Pathak15-Mar-05 18:16 
GeneralRe: Sending a web form as parameter Pin
see0716-Mar-05 11:59
see0716-Mar-05 11:59 
GeneralRe: Sending a web form as parameter Pin
see0722-Mar-05 7:00
see0722-Mar-05 7:00 
GeneralRe: Sending a web form as parameter Pin
see0722-Mar-05 12:20
see0722-Mar-05 12:20 
GeneralSystem.Timers problem Pin
sjhart15-Mar-05 7:17
sjhart15-Mar-05 7:17 
GeneralRe: System.Timers problem Pin
TylerBrinks15-Mar-05 8:20
TylerBrinks15-Mar-05 8:20 
GeneralPassing Safearray parameter to WebBrowser COM component Pin
simcho9915-Mar-05 3:45
simcho9915-Mar-05 3:45 
QuestionHow to show a child form when parent form is busy? Pin
oohungoo15-Mar-05 3:25
oohungoo15-Mar-05 3:25 

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.