Click here to Skip to main content
15,940,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hie!

I am using vb.net Win forms 2005 with ms access. I want to make my connectionstring global.
For that i am putting my connectionstring in app.config like:

XML
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />
  </configSections>
  <appSettings >
    <add key ="Test" value ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Transport.mdb" />
  </appSettings>

In my form i read it like:
VB
dim str as string
dim stringcn as string
strincn=configuratiomanager.appsetting("Test")
dim cn as oledbconnection
cn=new oledbconnection(stringcn)
cn.open()
str = "isert into tablename(column1) values(fieldname)"

but when i run it does not give any error but nothing gets stored in the database.

So what is the problem? Where is the mistake?
Please tell me.
Posted
Updated 15-Jul-10 19:56pm
v2

Hi,

Have you checked wherther you have been able to Open the connection? Please check the "State" property of connection object to make sure indeed connection is not created.

<br />
cn=new oledbconnection(stringcn);<br />
cn.open()<br />
if(cn.State==ConectionState.Open)<br />
{<br />
   MessageBox.Show("Connection Opened");<br />
}<br />
else<br />
{<br />
   MessageBox.Show("Connection Closed");<br />
}<br />
<br />


If you see connection is opened, then the problem might be in some other place. Then use try-catch block to identify if anything goes wrong.
 
Share this answer
 
Comments
Npanchasara 16-Jul-10 2:46am    
thank you..
i tried this one... connection is open but still it not store record in databse.
i didnt find the mistake what is the problem?

help me!
Arindam Tewary 16-Jul-10 4:31am    
Did you use try - catch block while using ExecuteNonQuery() and still you didnt get any error/exception ? Do you have a situation where you dont have any exception generated and still you done see data is updated? Please confirm.
If you get any exception/error after using try catch block please post the exception.
Give this a try a third down the page

Try this


you've made the connection now you have to insert the row into the database
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900