473,386 Members | 1,827 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,386 software developers and data experts.

Inserting data into a table....

JH
I have tried both suggested options shown below to insert simple string
values to an Access table, but to no avail. The executeNonQuery failed
miserably. I got the correct string values from each array items and were
able to check them using messagebox.show. BUT YET i AM UNABLE TO LOG THEM
INTO A TABLE.

Please I need help here
////// OPTION 1

//
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)" +

"Values(aryItemFields[0],aryItemFields[1],aryItemFields[2],aryItemFields[3])
", myConnection);

myOleCommand.ExecuteNonQuery();
//OPTION 2

//

aryItemFields[0] = fielInfo.fileName.ToString();

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) VALUES (?,?,?,?");

myOleCommand.Parameters.Add("@filename",OleDbType. VarChar).Value =
aryItemFields[0];

myOleCommand.Parameters.Add("@fsize",OleDbType.Var Char).Value =
aryItemFields[1];

myOleCommand.Parameters.Add("@fcreationTime",OleDb Type.VarChar).Value =
aryItemFields[2];

myOleCommand.Parameters.Add("@faccesstime",OleDbTy pe.VarChar).Value =
aryItemFields[3];

myOleCommand.ExecuteNonQuery();
Nov 16 '05 #1
3 1850
Hi,

How it fails?
Do you get an exception, if so what is the text of it.

I think that the second variant is the best, in the first you would have to
deal with controls chars ( ' , "," ) whether using parameters you eliminate
that.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"JH" <yh*******@yahoo.com> wrote in message
news:Ou**************@TK2MSFTNGP10.phx.gbl...
I have tried both suggested options shown below to insert simple string
values to an Access table, but to no avail. The executeNonQuery failed
miserably. I got the correct string values from each array items and were
able to check them using messagebox.show. BUT YET i AM UNABLE TO LOG THEM
INTO A TABLE.

Please I need help here
////// OPTION 1

//
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)" +

"Values(aryItemFields[0],aryItemFields[1],aryItemFields[2],aryItemFields[3]) ", myConnection);

myOleCommand.ExecuteNonQuery();
//OPTION 2

//

aryItemFields[0] = fielInfo.fileName.ToString();

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) VALUES (?,?,?,?");

myOleCommand.Parameters.Add("@filename",OleDbType. VarChar).Value =
aryItemFields[0];

myOleCommand.Parameters.Add("@fsize",OleDbType.Var Char).Value =
aryItemFields[1];

myOleCommand.Parameters.Add("@fcreationTime",OleDb Type.VarChar).Value =
aryItemFields[2];

myOleCommand.Parameters.Add("@faccesstime",OleDbTy pe.VarChar).Value =
aryItemFields[3];

myOleCommand.ExecuteNonQuery();

Nov 16 '05 #2
JH
I got it ..........ignore my question. If you use the code below it works
fine.
string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\WmiTestdb.mdb";
string strSQL = "INSERT INTO mytable1 (Name,Address) VALUES(?,?)";

OleDbConnection conn = new OleDbConnection(strConn);

conn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd = new OleDbCommand(strSQL,conn );
cmd.Parameters.Add("@Name", OleDbType.Char, 50).Value = aryItemFields[0];

cmd.Parameters.Add("@Address", OleDbType.Char, 50).Value = aryItemFields[1];

cmd.ExecuteNonQuery();


"JH" <yh*******@yahoo.com> wrote in message
news:Ou**************@TK2MSFTNGP10.phx.gbl...
I have tried both suggested options shown below to insert simple string
values to an Access table, but to no avail. The executeNonQuery failed
miserably. I got the correct string values from each array items and were
able to check them using messagebox.show. BUT YET i AM UNABLE TO LOG THEM
INTO A TABLE.

Please I need help here
////// OPTION 1

//
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)" +

"Values(aryItemFields[0],aryItemFields[1],aryItemFields[2],aryItemFields[3]) ", myConnection);

myOleCommand.ExecuteNonQuery();
//OPTION 2

//

aryItemFields[0] = fielInfo.fileName.ToString();

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) VALUES (?,?,?,?");

myOleCommand.Parameters.Add("@filename",OleDbType. VarChar).Value =
aryItemFields[0];

myOleCommand.Parameters.Add("@fsize",OleDbType.Var Char).Value =
aryItemFields[1];

myOleCommand.Parameters.Add("@fcreationTime",OleDb Type.VarChar).Value =
aryItemFields[2];

myOleCommand.Parameters.Add("@faccesstime",OleDbTy pe.VarChar).Value =
aryItemFields[3];

myOleCommand.ExecuteNonQuery();

Nov 16 '05 #3
I think your problem is that you are treating fsize & the datetimes as
if they were string, instead of a number & datetimes.

--
Truth,
James Curran
[erstwhile VC++ MVP]
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

"JH" <yh*******@yahoo.com> wrote in message
news:Ou**************@TK2MSFTNGP10.phx.gbl...
I have tried both suggested options shown below to insert simple string
values to an Access table, but to no avail. The executeNonQuery failed
miserably. I got the correct string values from each array items and were
able to check them using messagebox.show. BUT YET i AM UNABLE TO LOG THEM
INTO A TABLE.

Please I need help here
////// OPTION 1

//
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)" +

"Values(aryItemFields[0],aryItemFields[1],aryItemFields[2],aryItemFields[3]) ", myConnection);

myOleCommand.ExecuteNonQuery();
//OPTION 2

//

aryItemFields[0] = fielInfo.fileName.ToString();

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) VALUES (?,?,?,?");

myOleCommand.Parameters.Add("@filename",OleDbType. VarChar).Value =
aryItemFields[0];

myOleCommand.Parameters.Add("@fsize",OleDbType.Var Char).Value =
aryItemFields[1];

myOleCommand.Parameters.Add("@fcreationTime",OleDb Type.VarChar).Value =
aryItemFields[2];

myOleCommand.Parameters.Add("@faccesstime",OleDbTy pe.VarChar).Value =
aryItemFields[3];

myOleCommand.ExecuteNonQuery();

Nov 16 '05 #4

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

Similar topics

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...
1
by: madhuxml82 | last post by:
Dear Forum Members, I have generated an XML Schema and a Table of XMLType referencing the XML Schema. Now When I am Inserting the Data into the Table. I am getting the Error 0RA-30937: Error is...
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: 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. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.