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 / Windows Forms / WinForm Data Binding / February 2006

Tip: Looking for answers? Try searching our database.

From Datagrid to DataBase

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sylvain Bissonnette - 22 Feb 2006 01:25 GMT
Hi,

     I have a winform with a datagrid who is filled from a database, this
is working.  Now I had place
a "save" button on my form.  This is where I'm lost,  the main question is
how can I fill my database
with the new data from the datagrid?

   Any code snipper, url, hints will be welcome.

Thanks for your time
Sylvain Bissonnette
Cerebrus - 22 Feb 2006 14:14 GMT
Hi,

If you're loading data into the DataGrid using a DataAdapter and DataSet,
then just call the DataAdapter.Update(myDataSet) method. You're Dataset is
automatically updated with changes that occur in your Datagrid, and these
changes are then committed to the Database using the Update method.

Regards,

Cerebrus.

> Hi,
>
[quoted text clipped - 8 lines]
> Thanks for your time
> Sylvain Bissonnette
JSantora - 23 Feb 2006 16:46 GMT
Here you go, hope this helps...

   Private Sub frmStaff_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
       Try
           myQuery = "f_staff" '<<<SELECT StaffID, FirstName, MI,
LastName, Department FROM tblStaff ORDER BY StaffID;
           myComm = New SqlDataAdapter(myQuery, cn1)
           myComm.SelectCommand.CommandType =
CommandType.StoredProcedure

           ds = New DataSet
           myComm.Fill(ds, "Staff")

           SetupDataGrid(subStaff, ds.Tables("Staff"), , , , True) '
performs binding, adjusts column widths, etc.

       Catch ex As Exception
           DisplayException(ex, "EJS0504211130")
       Finally
           Me.Cursor = Cursors.Default
       End Try

   End Sub

   Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdSave.Click
       Me.BindingContext(ds.Tables("Staff")).EndCurrentEdit()
       Dim commandBuilder As SqlClient.SqlCommandBuilder = New
SqlClient.SqlCommandBuilder(myComm)
       myComm.Update(ds, "Staff")
       Me.Close()
   End Sub

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.