Frist add --- app.config
and write the code under app.config------
------------------------------
[appSettings ]
[add key ="cont1" value ="server=.;trusted_connection=yes;database=stest" /]
[/appSettings]
------------------------------
###############write the code under db class################and write the code under app.config------
------------------------------
[add key ="cont1" value ="server=.;trusted_connection=yes;database=stest" /]
[/appSettings]
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Public Class db
Public cont As String = ConfigurationSettings.AppSettings("cont1")
Public Function getdata(ByVal myqry As String) As DataTable 'This function use getdata from db
Dim cn As New SqlConnection(cont)
Dim ds As New DataSet
Dim td As New DataTable
Try
Dim da As New SqlDataAdapter(myqry, cn)
da.Fill(ds)
td = ds.Tables(0)
Catch ex As Exception
End Try
Return td
End Function
Public Function excute(ByVal myqry As String) As Boolean 'This function insert,update data in to db
Dim cn As New SqlConnection(cont)
Dim ds As New DataSet
Try
Dim da As New SqlDataAdapter(myqry, cn)
da.Fill(ds)
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try
Return True
End Function
End Class
###############################################