Question : How to create a DB connection at one place/page so that we can use that connection for all pages/forms/windows.what r the steps ned to be performed. if question not clear,let me know.
Protected Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs) Dim sqlConn As SqlConnection Dim sqlCmd As SqlCommand Dim strConnection As String
Try 'Get connection string from Web.Config strConnection = ConfigurationSettings.AppSettings("ConnectionString") sqlConn = New SqlConnection(strConnection) sqlCmd = New SqlCommand("SELECT * FROM Customers WHERE " _ & "(CompanyName LIKE 'A%') OR (CompanyName LIKE 'B%')", sqlConn) sqlConn.Open() dataGrid.DataSource = sqlCmd.ExecuteReader() dataGrid.DataBind() Catch ex As Exception Response.Write(ex.ToString & "<br>") Finally sqlConn.Close() End Try End Sub
End Class
If you have the better answer, then send it to us. We will display your answer after the approval.