im a beginner wid vb .net and need to clear the air wid connecting a database file created on sql server 2008r2 wid vb.net 2008 for a project..plz nebody help from scratch regardng retriving,insertng n modifyng data using vb.net code..awaiting....

Recommended Answers

All 5 Replies

You start by reading books. "Wrox Professional Visual Basic" and "Sybex Mastering Visual Basic" both contain very good sections on database programming. Don't expect us to be personal tutors and hold your hand through the learning process.

hello !
use this code ,

Dim MyConn As New SqlConnection("Data Source=(local);Initial Catalog=dbname;Integrated Security=SSPI;")

Regards

M.Waqas Aslam

im a beginner wid vb .net and need to clear the air wid connecting a database file created on sql server 2008r2 wid vb.net 2008 for a project..plz nebody help from scratch regardng retriving,insertng n modifyng data using vb.net code..awaiting....

u can create a module and call it every time u need a connection

Imports System.Data.SqlClient

Module DBConnection
    Public Connection As SqlConnection = New SqlConnection()
    Public Function Open_DB_Connection() As String
        Try
            Connection.ConnectionString = "Server=.\SQLEXPRESS;" & _
                    "Database=DBName;Trusted_Connection=True"
            Connection.Open()
            Return "Success"
        Catch ex As Exception
            Debug.Print(ex.Message & "in DBConnection_Module")
            Return "Fail"
            Exit Function
        End Try
    End Function

    Public Function Close_DB_Connection() As String
        Try
            Connection.Close()
            Return "Success"
        Catch ex As Exception
            Debug.Print(ex.Message & "in DBConnection_Module")
            Return "Fail"
            Exit Function
        End Try
    End Function
End Module

calling DB connection in ur forms

Dim Open_DB_Con As String
Open_DB_Con = Open_DB_Connection()

--your SQl query part goes here

Dim Close_DB_Con As String
Close_DB_Con = Close_DB_Connection()
Imports System.Data.SqlClient
Module ConnectionUsingIP
    Public Con As SqlConnection
    Public cons As String
    Public usertype As String


    Public Sub main()
cons = "Data Source=127.0.0.1,49166;Network Library=DBMSSOCN;Initial Catalog=packwelldata;User ID=sa;Password=bedarsi;Trusted_Connection=False;"
        Con = New SqlConnection(cons)
        Try
            Con.Open()
            'MsgBox("Server Connection is Open ! ")
            Con.Close()
        Catch ex As Exception
            MsgBox("Sorry Can not open connection ! ")

        End Try


    End Sub


End Module
'note:  try enabled your TCP/IP in the sql server configuration manager and restart
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.