473,396 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Inserting into a Access DB

Hello All,

Sure this is something simple but it is driving me mad! I have the code below which I want to use to insert Data from my C# programme into access database.

However everytime that it tries to write to the DB it throws a error.

Expand|Select|Wrap|Line Numbers
  1.  conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
  2.                 @"Data source= C:\db1.mdb; Persist Security Info=False";            
  3.  
  4.  
  5.                 OleDbCommand cmd = new OleDbCommand();
  6.  
  7.               try
  8.                 {
  9.                 conn.Open();
  10.                 cmd = conn.CreateCommand();
  11.                 cmd.CommandText = "INSERT INTO logData([IP Address],[Username],[Referrer],[url])VALUES(" + savedData + ",'" + savedData1 + ",'" + savedData2 + ",'" + savedData3 + "');";
  12.  
  13.                 cmd.ExecuteNonQuery();
  14.                 }
  15.                 catch (Exception ex)
  16.                 {
  17.                  MessageBox.Show("Failed to connect to data source");
  18.                 }
  19.               finally
  20.                 {
  21.             conn.Close();
  22.                 }
savedData through to savedData3 are string variables that have been populated with either numbers a "-" or text. Can anyone help as to why this wont save to my DB?

Thanks
Dec 10 '10 #1
1 1841
In your catch block, you should output the error message (ex.Message) and the stacktrace.


Please let us know what error your code is throwing =)
Dec 14 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Tom | last post by:
Hi I am looking for an optimal data-structure in order to replace a map<int,float>. I use it as some kind of sparse array representation. The facts: - the population in the data-structures...
3
by: pbbriggs | last post by:
I will try to be as descriptive as possible, but this error has me stumped and I am not sure what relevant info to include.... I am running Access XP on a Windows XP machine. I initially began...
2
by: moller | last post by:
Im looking in to the possibility of moving from mySQL to an access database. My reasons are: (1) Database is single user. (2) Database local on users PC. (3) Database has only 8 tables where 4...
11
by: Danny J. Lesandrini | last post by:
Has anyone else noticed this? I searched group archives and found nothing, but it's really starting to irritate me big time. Here's the steps to reproduce the problem: Copy something to the...
1
by: Joe | last post by:
Hi, I have an asp.net page that opens up a connection to MS access DB and does insert into DB. I am using close() and setting the connection object to Nothing after I am done with inserting a...
9
by: dan | last post by:
within a loop i am building a sql insert statement to run against my (programatically created) mdb. it works but it seems unreasonably SLOW! Sorry, dont have the code here but the jist is very...
23
by: Gloops | last post by:
Hello everybody, Is anyone able to give me some indications about how to develop an Access interface for an Oracle database ? I dispose of Access 2003 (11.6566.8107) SP2, Oracle 9i 9.2.0.1.0...
2
by: hakkatil | last post by:
Hi to all, I have a page that inserts excel sheet to access database. I am using asp. What I want to do is to check the inserting record if it is in the database. Basicly checking the dublicate...
5
by: rando1000 | last post by:
Okay, here's my situation. I need to loop through a file, inserting records based on a number field (in order) and if the character in a certain field = "##", I need to insert a blank record. ...
3
by: Vinda | last post by:
Hi Bytes, Using a previous question as a base Access 2000 Inserting multiple rows based on a date range. I also wanted to insert multiple rows into a table according to a date range supplied by a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.