473,404 Members | 2,187 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,404 software developers and data experts.

Inserting data into a table using c#

JH
I have checked my return strings and all are correct. But when I want to
insert them into an Access database table it fails. However, if I change the
insert values just to simple strings it works. Yet I have all the
aryItemFields[i] values as strings correctly. Any HINT>>>>PLEASE.
...(THIS PIECE OF CODE DOES NOT WORK.....). ...
aryItemFields[0] = fielInfo.fileName;

aryItemFields[1] = fielInfo.size.ToString();

aryItemFields[2] = fielInfo.creationTime.ToString();

aryItemFields[3] = fielInfo.lastAccessTime.ToString();

myOleCommand = new OleDbCommand("INSERT INTO mytable1
filename,fsize,fcreationTime,fAccessTime) ValuesaryItemFields[0]
,aryItemFields[1],aryItemFields[2],aryItemFields[3])", myConnection);

(HOWEVER THIS ONE WORKS FINE......)

myOleCommand = new OleDbCommand("INSERT INTO mytable1
filename,fsize,fcreationTime,fAccessTime) Values('a','b','c','d')",
myConnection);
Nov 16 '05 #1
2 11127
Well, the key point is the presence of the single quotes in the statement
that works. Do the same on your real data, such as:

aryItemFields[1] = "'" + fielInfo.size.ToString() + "'";

for all fields that are defined as one of the string types in the column
definitions, and you'll be on your way.

Tom Dacon
Dacon Software Consulting

"JH" <yh*******@yahoo.com> wrote in message
news:OX**************@TK2MSFTNGP14.phx.gbl...
I have checked my return strings and all are correct. But when I want to
insert them into an Access database table it fails. However, if I change
the
insert values just to simple strings it works. Yet I have all the
aryItemFields[i] values as strings correctly. Any HINT>>>>PLEASE.
..(THIS PIECE OF CODE DOES NOT WORK.....). ...
aryItemFields[0] = fielInfo.fileName;

aryItemFields[1] = fielInfo.size.ToString();

aryItemFields[2] = fielInfo.creationTime.ToString();

aryItemFields[3] = fielInfo.lastAccessTime.ToString();

myOleCommand = new OleDbCommand("INSERT INTO mytable1
filename,fsize,fcreationTime,fAccessTime) ValuesaryItemFields[0]
,aryItemFields[1],aryItemFields[2],aryItemFields[3])", myConnection);

(HOWEVER THIS ONE WORKS FINE......)

myOleCommand = new OleDbCommand("INSERT INTO mytable1
filename,fsize,fcreationTime,fAccessTime) Values('a','b','c','d')",
myConnection);

Nov 16 '05 #2
You need to use parameterized queries:

myOleCommand = new OleDbCommand("INSERT INTO mytable1
(filename,fsize,fcreationTime,fAccessTime) VALUES (?,?,?,?");
myOleCommand.Parameters.Add("@filename",OleDbType. Whatever).Value =
aryItemFields[0];
// etc.

--Bob

"JH" <yh*******@yahoo.com> wrote in message
news:OX**************@TK2MSFTNGP14.phx.gbl...
I have checked my return strings and all are correct. But when I want to
insert them into an Access database table it fails. However, if I change
the
insert values just to simple strings it works. Yet I have all the
aryItemFields[i] values as strings correctly. Any HINT>>>>PLEASE.
..(THIS PIECE OF CODE DOES NOT WORK.....). ...
aryItemFields[0] = fielInfo.fileName;

aryItemFields[1] = fielInfo.size.ToString();

aryItemFields[2] = fielInfo.creationTime.ToString();

aryItemFields[3] = fielInfo.lastAccessTime.ToString();

myOleCommand = new OleDbCommand("INSERT INTO mytable1
filename,fsize,fcreationTime,fAccessTime) ValuesaryItemFields[0]
,aryItemFields[1],aryItemFields[2],aryItemFields[3])", myConnection);

(HOWEVER THIS ONE WORKS FINE......)

myOleCommand = new OleDbCommand("INSERT INTO mytable1
filename,fsize,fcreationTime,fAccessTime) Values('a','b','c','d')",
myConnection);

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Marko Poutiainen | last post by:
Situation: We had to make our SQLServer 2000 database multi-lingual. That is, certain things (such as product names) in the database should be shown in the language the user is using (Finnish,...
3
by: Joachim Klassen | last post by:
Hi all, first apologies if this question looks the same as another one I recently posted - its a different thing but for the same szenario:-). We are having performance problems when...
2
by: Charles Wilt | last post by:
I have a IBM iSeries (aka AS-400) running v5r3 of OS/400 that I access via a linked server from SQL Server 2000. The following select works fine: select * from...
11
by: c676228 | last post by:
Hi everyone, I am just wodering in asp program, if there is anybody writing store procedure for inserting data into database since there are so many parameters need to be passed into store...
3
by: rcoco | last post by:
Hi, I want to share this problem. I have a datagrid that will help me Insert data into sql database. So I made a button On my form so that when I press the button a new row on datagrid should be...
2
by: Etayki | last post by:
Hi! I am trying to insert data into a MS SQL Database from a Console Application written in VB.net I have already created the table in the database and I am able to read values. When I insert a...
5
by: dos360 | last post by:
Hello, I have two tables, one is a list of activities, the other a list of participants. I want to insert one record in the activities table and then using its identity column as foreign key, I...
2
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography...
2
by: cluce | last post by:
I am trying to read a csv file with user info (username, password, email, address, city, zip, state, etc.) I am inserting the username, password, email into the aspnet_memberhsip table using the...
5
by: billelev | last post by:
I have a large array of data (1000 x 40 x 3) that I am inserting into a database table. It is incredibly slow, and so I was wondering if there is a quicker way of inserting array data into a table....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.