CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2002
    Posts
    788

    2 beginner questions

    hi,

    beginner questions..

    1)
    i am binding a datagrid view to a sql database. How can i make it such a way that if i change the data in the grid view, the same data will get updated into the database?

    2)if i want to update a particular field in my sql database, how to do it in csharp? i manage to write codes as below only, after much searching in the internet.

    Code:
        SqlConnection myConnection = new SqlConnection("Data Source=(local); Trusted_Connection=yes");
               SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter("select * from Table1", myConnection);
    However,,,

    NOTE: When i add a datagridview and bind it to my database, visual studio (2008) automatically created the following for me.

    table1TableAdapter
    table1BindingSource
    testDataSet

    I have one table in my DB. I just lost on how to make use of this to update my DB. I believe it is possible for me to use the above objects to update individual field in my DB?
    Last edited by mce; March 18th, 2008 at 03:34 AM.

  2. #2
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: 2 beginner questions

    Hi,

    Are you using a version of Visual Studio? If you are I assume that you've setup a data data source (most likely a SqlDataSource). You can configure that data source with the SQL statements or stored procedures that should executed for updates. Have you done that?

    There are different ways of doing things in the .NET framework but at the end of the day you must use some core classes.
    SqlConnection
    SqlCommand
    If you want to read data you can use SqlDataReader or SqlDataAdapter as you've found in an example. I would really advise recommend that you look at MSDN first. It has everything you would need. Search on the internet after you've looked at MSDN.

  3. #3
    Join Date
    Jul 2002
    Posts
    788

    Re: 2 beginner questions

    assuming i have filled my dataset from the datasource, let's call it testDataSet, how do i reach an individual cell/field in the table so that i can modify and save it?

  4. #4
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: 2 beginner questions

    Read the DataWalkthrough 2.0 (DW2) link in my signature, section on creating a simple data app
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured