Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / September 2005

Tip: Looking for answers? Try searching our database.

Database doesn't update from datagrid using dataset

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Assimalyst - 30 Sep 2005 11:09 GMT
Hi,

I'm attempting to update an SQL Server database from a datagrid. I have
followed one of microsofts walkthroughs as far as possible, but I am
using stored procedures where it did not, though i don't think that
should be a problem.

Here's the code:

private void DataGrid1_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
    string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();

    TextBox tb;
    tb = (TextBox)(e.Item.Cells[5].Controls[0]);
    string strHistology = tb.Text;

    sqlDataAdapter1.UpdateCommand.Parameters["@sampleNo"].Value = key;
    sqlDataAdapter1.UpdateCommand.Parameters["@histology"].Value =
strHistology;

    sqlDataAdapter1.Update(dsSample1);

    DataGrid1.EditItemIndex = -1;
}

The string values key & strHistology are getting written correctly (87
& Squamous respectively) and the update query works with these values
using query analyser, but for some reason the updates are either not
been written to the dataset and/or the database using the above code.

Any ideas?

Thanks.
AMDRIT - 30 Sep 2005 15:09 GMT
It appears as though you are trying to update a dataset with a single
adapter, that is not how it is supposed to work.
If you setting the datasource of the datagrid to a datatable (part of a
dataset). Then all you have to do is update the datatable, you don't even
need to read the values from the grid to do it.

example:

class temp

public readonly property daTable as dataadapter

   dim objcmdBuilder as commandbuilder
   dim objdaTable as dataadataper
   dim objConn as dataconnection

   objConn = new dataconnection = "someconnnectrionstring"

   objdaTable = new dataadapter("SomeSelectStatement",objConn)
  objcmdBuilder = new commandbuilder(objdaTable)

  return objdaTable

end property

end class

class Form1

private m_CTemp as Temp

sub UpdateData()
   'I do not pretend to know what is in the webcontrol for a datagrid
   'I imagine that is is still the same as what is in the winform control

   dim dt as Datatable

   'Get all the changes from last postback
   dt = ctype(datagrid1.datasource, datatable).getchanges(added, updated,
deleted)

   'Apply them to the repository
   if not dt is nothing then  m_CTemp.dsTable.update(dt)

end sub

end Class

I know you are using c#, I hope you can get the just of what I am doing from
my VB sample.

hope that helps.

> Hi,
>
[quoted text clipped - 31 lines]
>
> Thanks.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.