Hi All,
I am new in vb.net. I am using Visual Studio 2003 and sql 2000.
I want to use configuration manager to retrive the connection from app.config

But I am getting error " Name 'ConfigurationManager' is not declared"

the code, I written, is as follows:
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Configuration.ConfigurationSettings
-----------------------------------------------------------------
Namespace PC

Public Class DataEntry
Inherits System.Windows.Forms.Form

Public Shared Function GetConnectionString(ByVal conName As String) As String
Dim strReturn As New String("")
If Not String.IsNullOrEmpty(conName) Then
strReturn = ConfigurationManager.ConnectionString(conName).ConnectionString
Else
strReturn = ConfigurationManager.ConnectionString("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=ACCOUNTS;Data Source=winxp").ConnectionString

End If
Return strReturn

End Function

Please help me out...

ConfigurationManager did not exist until .net 2.0, use visual studio 2005 to be able to use it.

ConfigurationManager did not exist until .net 2.0, use visual studio 2005 to be able to use it.

thanks dear. but can u tell me if i can use other code instead of configurationmanager?
i will be greatful of u if u could provide me alternate code..

And i think bindingsource is also not exist in VS 2003. Pls give me the alternate for binding source also if possible.

with regards

shailesh

'In Module
'Declare outside of class
Imports System.Data
Imports System.Data.SqlClient

Module Koneksi
    Public conn As SqlConnection
    Public Function GetConnect()
        conn = New SqlConnection("server = MyServerName;database = MyDatabaseName;Trusted_Connection = yes")
        Return conn
    End Function
End Module

Ex : load data in datagrid

'In Form
'Declare outside of class
Imports System.Data
Imports System.Data.SqlClient

'Procedure To show data in DataGrid
Private Sub ShowDataGrid()
    Dim conn As SqlConnection
    Dim cmdStudent As New SqlCommand
    Dim daStudent As New SqlDataAdapter
    Dim dsStudent As New DataSet
    Dim dtStudent As New DataTable

    conn = GetConnect()
    Try
		cmdStudent = conn.CreateCommand
		cmdStudent.CommandText = "SELECT * FROM YourTableName"
		daStudent.SelectCommand = cmdStudent
		daStudent.Fill(dsStudent, "YourTableName")
		dgStudent.DataSource = dsStudent
		dgStudent.DataMember = "YourTableName"
		dgStudent.ReadOnly = True
    Catch ex As Exception
        MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OKOnly, "Connection Error !!")
    End Try
End Sub

' Call procedure ShowDataGrid() on event Form Load 
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    ShowDataGrid()  ' Load data to view in data grid
End Sub

In .net 1.1 you can use the configuration namespace

System.Configuration.AppSettings

but as stated, in .net 2.0 this is deprecated

Thanx . I will try n then reply again.

with warm regards

Shailesh

'In Module
'Declare outside of class
Imports System.Data
Imports System.Data.SqlClient

Module Koneksi
    Public conn As SqlConnection
    Public Function GetConnect()
        conn = New SqlConnection("server = MyServerName;database = MyDatabaseName;Trusted_Connection = yes")
        Return conn
    End Function
End Module

Ex : load data in datagrid

'In Form
'Declare outside of class
Imports System.Data
Imports System.Data.SqlClient

'Procedure To show data in DataGrid
Private Sub ShowDataGrid()
    Dim conn As SqlConnection
    Dim cmdStudent As New SqlCommand
    Dim daStudent As New SqlDataAdapter
    Dim dsStudent As New DataSet
    Dim dtStudent As New DataTable

    conn = GetConnect()
    Try
		cmdStudent = conn.CreateCommand
		cmdStudent.CommandText = "SELECT * FROM YourTableName"
		daStudent.SelectCommand = cmdStudent
		daStudent.Fill(dsStudent, "YourTableName")
		dgStudent.DataSource = dsStudent
		dgStudent.DataMember = "YourTableName"
		dgStudent.ReadOnly = True
    Catch ex As Exception
        MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OKOnly, "Connection Error !!")
    End Try
End Sub

' Call procedure ShowDataGrid() on event Form Load 
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    ShowDataGrid()  ' Load data to view in data grid
End Sub
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.