CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1

    Unhappy How to do this in a better way%

    It might not be the best way to navigate through a recordset, but is there an actual way to do the following code better?

    Code:
    private void button1_Click(object sender, System.EventArgs e)
    {
       ADODB.Connection objConnection = new ADODB.ConnectionClass();
       ADODB.Recordset rsData = new ADODB.RecordsetClass();
    
       objConnection.Open("Provider=SQLOLEDB;User ID=daing;Password=daing;Initial Catalog=D42DAIng;Data Source=HERCULES", "daing", "daing", 0);
    
       rsData.Open("select * from t016_achat", objConnection, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly, 1);
    
       while (!rsData.EOF)
       {
           MessageBox.Show(rsData.Fields["CleUniqueA"].Value.ToString());
    		rsData.MoveNext();
       }
    
    }
    Funny, I found no information at all on the RecordsetClass, so I guess this is not the way to proceed!!

  2. #2
    Join Date
    Jul 2002
    Location
    .NET 2.0/.NET 3.0/.NET 3.5 VS2005/VS2008
    Posts
    284
    Try adding a Dataset to your project and fill it like this.

    SqlDataAdapter1.Fill(dataSet1);

    And after that you can access the data from there with this:

    string name;

    name = (string) dataSet1.Tables["blahblah"]["name"];

    MessageBox.Show(this,name);
    WM.

    What about weapons of mass construction?

  3. #3
    Join Date
    Oct 2001
    Location
    Norway
    Posts
    265
    Any particular reason you're not using ADO.NET?

  4. #4
    Join Date
    Jul 2002
    Location
    .NET 2.0/.NET 3.0/.NET 3.5 VS2005/VS2008
    Posts
    284
    No particular reason
    But I agree it's smarter to use ADO.NET
    WM.

    What about weapons of mass construction?

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