Saturday, September 29, 2012

how to Connect VB .NET and SQL SERVER 2005


  1. Create a new Module for the connection string.
  2. Create a Public Funtion so you can access it anywhere in your project.
  3. paste this code.
  4. Change the Data Source to your computer name/ sqlexpress.
  5. change the initial catalog to you database name.
  6. change user id and password if applicable.
Public Function ExecuteQuery(ByVal Query As String) As DataTable
        Dim sqlcon As New SqlConnection("Data Source=CHARLON-PC\SQLEXPRESS;Initial Catalog=dbCyclenessTrading;User ID=sa;Password=admin")
        Dim sqlda As New SqlDataAdapter(Query, sqlcon)
        Dim sqlcb As New SqlCommandBuilder(sqlda)
        Dim dt As New DataTable
        sqlda.Fill(dt)
        Return dt
    End Function




0 comments:

Post a Comment