Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to connect VB to MS SQL 1

Status
Not open for further replies.

paul102384

Programmer
Oct 5, 2007
30
hi to all programmers,

I'm not familiar on how to connect Visual Basic to MS SQL,becaused instead of MS SQL i used MS Acces as my back-end.Can anyone help or tell me on how to connect VB to MS SQl.
 
There are some prebuild methods in 2005, but you can also use something like the function below and bind it to something like a datagrid.

Code:
    Private Function GetData(ByVal strSQL As String) As DataSet
        Try
            Dim conn As New SqlClient.SqlConnection("Your Connection String Here.")
            Dim cmd As New SqlClient.SqlCommand(strSQL, conn)
            Dim da As New SqlClient.SqlDataAdapter(cmd)
            Dim dsRet As New DataSet

            da.Fill(dsRet)
            Return dsRet
        Catch ex As Exception
            'Handle any errors here, or just throw them back.
            Throw ex
        End Try
    End Function

Senior Software Developer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top