2 Replies - 4917 Views - Last Post: 18 January 2009 - 02:21 AM Rate Topic: -----

#1 omigod  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-January 09

Can't connect database use app.config. Help me!

Posted 17 January 2009 - 09:03 PM

Dear,

Plz help me, i can't connect database and bind it in DataGridView when i use app.config for connectionstring. I use VB.NET and MS Access.
Thanks in advance!!! :-*

Here is my code in app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
	<add key="Datapath" value="Provider=Microsoft.Jet.OLEDB.4.0;data source=nfsc.mdb; Integrated Security = false/>
  </appSettings>
</configuration>


and in Form
Imports System.Data
Imports System.Data.OleDb
Imports System.Configuration
Imports System.Configuration.ConfigurationSettings
Imports System.Configuration.ConfigurationManager
Imports nfsc.My.MySettings

Public Class frmView
	Inherits System.Windows.Forms.Form
 
   Dim ds As New DataSet
	Dim dt As New DataTable
	Dim cmd As New OleDb.OleDbCommand
	Dim oda As New OleDb.OleDbDataAdapter
	Dim conn As New OleDbConnection
	Dim str As String = ConfigurationManager.AppSettings.Item("ConnectionString")
   
	Private Sub frmView_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
			 conn.ConnectionString = str
			Me.ds.Clear()
		Try
			conn.CreateCommand()
			cmd.CommandText = "SElect * from tblNFSC"
			Me.oda.SelectCommand = cmd
			conn.Open()
			Me.oda.Fill(Me.ds, "tblNFSC")
			Me.dgrid.DataSource = ds
			Me.dgrid.DataMember = "tblNFSC"
			Me.txtCode.DataBindings.Add("Text", Me.ds, "tblNFSC.Code")


Is This A Good Question/Topic? 0
  • +

Replies To: Can't connect database use app.config. Help me!

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Can't connect database use app.config. Help me!

Posted 17 January 2009 - 09:19 PM

Use "Datapath" instead of "ConnectionString", per the key in the element.

Dim str As String = ConfigurationManager.AppSettings.Item("Datapath")

Was This Post Helpful? 0
  • +
  • -

#3 omigod  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-January 09

Re: Can't connect database use app.config. Help me!

Posted 18 January 2009 - 02:21 AM

View PostJayman, on 17 Jan, 2009 - 08:19 PM, said:

Use "Datapath" instead of "ConnectionString", per the key in the element.

Dim str As String = ConfigurationManager.AppSettings.Item("Datapath")



Thanks u so much, Jayman :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1