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

Not valid date, importing from csv to access

Sl1ver
196 100+
im importing text from a csv file to a access database
i create my parameter
Expand|Select|Wrap|Line Numbers
  1. OleDbParameter Param7 = new OleDbParameter("@Param7", OleDbType.DBTimeStamp);
  2.                         cmd.Parameters.Add(Param7);
  3.  
then i convert the read value to date time
Expand|Select|Wrap|Line Numbers
  1. cmd.Parameters["@Param7"].Value = Convert.ToDateTime(columns[6].Replace("\"", ""));
  2.  
it stops by the second piece of code i put in saying
"String was not recognized as a valid DateTime"

What am i doing wrong?
Aug 5 '09 #1
1 2060
tlhintoq
3,525 Expert 2GB
Doing everything in one line might seem clean, but it makes it hard to check assumptions as well as hard to catch exceptions.

Instead of doing it all in one line, try breaking it down into a couple lines, so you can step through it and see where something is not as you expected.
Expand|Select|Wrap|Line Numbers
  1. cmd.Parameters["@Param7"].Value = Convert.ToDateTime(columns[6].Replace("\"", ""));
  2.  
Expand|Select|Wrap|Line Numbers
  1. string newDateAsString = columns[6].Replace("\"", "");
  2. MessageBox.Show(newDateAsString, "Does this look like a date?");
  3.  
  4. cmd.Parameters["@Param7"].Value = Convert.ToDateTime(newDateAsString);
  5.  
  6.  
Aug 5 '09 #2

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

Similar topics

4
by: Christine | last post by:
I am having the strangest problem. I use the Date function in several of my forms and modules in an Access 2000 mdb. Lately, wherever in my code (in this one mdb) I use the Date function, it...
6
by: Mike Charney | last post by:
Is there a way to check a files date and time stamp from VBA in access. I have a need check a date stamp on a file that I am importing. Thanks in advance, Mike m charney at dunlap hospital...
14
by: ml_sauls | last post by:
I've built a system to enter and manage purchase orders. This is in use by >10 clients. Some use it in Access 97, most are in A2k. About half use it through a Citrix implementation. It is...
2
by: ScardyBob | last post by:
Hello, I am having trouble importing data from an Excel Worksheet. When I try to import the data, everything works except certain columns that contain dates, where it replaces the date with a...
16
by: pmatzek | last post by:
I am attempting to automate a process involving importing a .txt file into an existing table, changing a date in each record, then exporting the table, again as a .txt file. One field contains a...
3
by: veaux | last post by:
The date format mmddyyyy is common but I realize it's not a standard format in Access. There must be a simple way to provide this format to Access so it treats it as a date? In past, I play with...
1
by: trevorjhughes | last post by:
I am running an import of some date/time values that have come from a Cognos query. These values are in a CSV file and I want to import them into access. The CSV file would show the value thus:...
1
by: BulbFresh | last post by:
Hi, Quick one for you, i'm importing a file which has a long date and time format, so once imported i update each date field with the correct format (dd/mm/yyyy). I wrote this in on click of a...
2
by: Mimi | last post by:
In Access 2007, I have successfully imported a text file with fixed width fields. However the import did not correctly interpret a date. In the text file the date field had no delimiter, was just...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.