We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

dataconnection

VBdotnet2005
VBdotnet2005 asked
on
Medium Priority
186 Views
Last Modified: 2010-04-23
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 .
Comment
Watch Question

Database Engineer
CERTIFIED EXPERT
Top Expert 2005
Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Is this vb6?
Brian CroweDatabase Engineer
CERTIFIED EXPERT
Top Expert 2005

Commented:
nope...vb.net.  You did post this question in a VB.Net Topic Area :-)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.