dataconnection

How many ways can we connect to database(database connection, data adapter, dataset)? Also, you could give me a sample how to display data (from SQL2000 server) to a datagrid?  I'm a newbie .
VBdotnet2005Asked:
Who is Participating?
 
Brian CroweDatabase AdministratorCommented:
dataadapter and datareader are the typical ways.

private ds as new dataset
private da as new sqldataadapter
...
private sub load(...) handles mybase.load
   DefineAdapter
   da.fill(ds)
   myDataGrid.datasource = ds.tables("Data")
end sub

private sub DefineAdapter()
   with da
      .selectcommand = new sqlcommand
      with .selectcommand
         .connection = new sqlconnection({connection string})
         .commandtext = "SELECT col1, col2, col3 FROM myTable"
      end with
 
      'optionally add insertcommand/updatecommand/deletecommand if you want to update your database from the app

      .acceptchangesduringfill = true
      .tablemappings.add("Table", "Data")
   end with
end sub
0
 
VBdotnet2005Author Commented:
Is this vb6?
0
 
Brian CroweDatabase AdministratorCommented:
nope...vb.net.  You did post this question in a VB.Net Topic Area :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.