Results 1 to 6 of 6

Thread: A few simple ADO.NET questions [Resolved]

Threaded View

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    A few simple ADO.NET questions [Resolved]

    Going through the book, studying as usual, I was instructed that when I want to use the SQLDataAdapter, SQLConnection objects, and generate a DataSet object, and then bind my control (textbox, datagrid, whatever) to it to get the value.

    My first question is:

    Is this the way most of you do it? Or do you prefer doing it through code?

    I did it the way described above, and saw that it generated a lot of code. So, my VB6-remnant brain assumed that using these objects to connect to a database would be as inefficient as using the ADODC control in VB6 (You guys remember that one? )

    So, I tried to do it through code. Here is what I came up with so far:

    VB Code:
    1. Dim scSqlConn As New SqlConnection
    2.         scSqlConn.ConnectionString = "Data Source=(local);" & _
    3.                             "Initial Catalog=NorthWind;uid=sa;pwd=;" & _
    4.                             "Integrated Security=SSPI"
    5.         scSqlConn.Open()
    6.  
    7.         'data set, data adapter
    8.  
    9.         Dim dsDataSet As New DataSet
    10.         Dim daDataAdapter As New SqlDataAdapter
    11.         Dim cmdSELECTCOMMAND As New SqlCommand
    12.         cmdSELECTCOMMAND.CommandText = "SELECT * FROM Customers;"
    13.         cmdSELECTCOMMAND.Connection = scSqlConn
    14.  
    15.  
    16.         daDataAdapter.SelectCommand = cmdSELECTCOMMAND
    17.         daDataAdapter.Fill(dsDataSet, "Customers")

    Second question:
    Am I doing it right? Am I missing something?

    Third question:
    I am simply trying to set a Textbox1.Text property to a value in the table.

    In VB6, this was:

    VB Code:
    1. TextBox1.Text = Objrs.Fields(0).Value

    I can't figure out how to do that in ADO.NET. Any ideas what I should do?



    Thanks.
    Last edited by mendhak; May 24th, 2004 at 11:28 AM.

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