Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 202
  • Last Modified:

Using Microsoft SQL Server on VB.NET

I am building a simple form application that needs to access my Microsoft SQL Server (I'm running 2005 Express Edition).

Alright, I've gotten to the point where I've established the connection to my Visual Basic application now I would like to do a statement like "SELECT * FROM mydb.mytable". How do I do that and what is the best way to look at the results from that query. Code would help. Thank you for the help, I realize this is an easy question for you experts but I'd like a starting point.
0
Linky
Asked:
Linky
1 Solution
 
riyazthadCommented:
       Dim cn As New SqlClient.SqlConnection
        cn.ConnectionString = "Give ur connection string here"
        cn.Open()

        Dim ds As DataSet = New DataSet

        Dim MyAdapter As SqlClient.SqlDataAdapter
        MyAdapter  = New SqlClient.SqlDataAdapter ("select * from mytable", cn)

        MyAdapter.Fill(ds)

        For each dr as DataRow in ds.tables(0).rows
              MessageBox.show(dr("field1"))
              MessageBox.show(dr("field2"))
              MessageBox.show(dr("field3"))
              'You can navigate thru all records here.    
        End For
0
 
LinkyAuthor Commented:
Nifty. Thanks.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now