Wrong syntax when trying to save CSV file column as string
-
Hi, I am parsing a CSV file and storing it in database. All the table fields are varchar. The CSV file has a column called Date which is in the format 11/11/2007 where i checked the Format Cells it displays date. The problem is when i save this field in the database it automatically saves as 11/11/2007 12:00:00 AM. I need not want to the time to get saved. Can any one please help me out.
-
Hi, I am parsing a CSV file and storing it in database. All the table fields are varchar. The CSV file has a column called Date which is in the format 11/11/2007 where i checked the Format Cells it displays date. The problem is when i save this field in the database it automatically saves as 11/11/2007 12:00:00 AM. I need not want to the time to get saved. Can any one please help me out.
You might be using a
DateTime
/Smalldatetime
data type. It always append time with it. Try usingvarchar
instead.
-
You might be using a
DateTime
/Smalldatetime
data type. It always append time with it. Try usingvarchar
instead.
-
Are you reading this columns value through a datetime variable in page ?
-
Are you reading this columns value through a datetime variable in page ?
This is what i do string ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=\"Text;HDR=No;FMT=Delimited\\\""; System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(ConStr); System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter("Select * from " + file, conn); da.Fill(ds, "TextFile"); DGCsv.DataSource = ds.Tables[0].DefaultView;
-
Hi, I am parsing a CSV file and storing it in database. All the table fields are varchar. The CSV file has a column called Date which is in the format 11/11/2007 where i checked the Format Cells it displays date. The problem is when i save this field in the database it automatically saves as 11/11/2007 12:00:00 AM. I need not want to the time to get saved. Can any one please help me out.
A DataTime value always has a date and a time component. If you don't specify the time component, it becomes zero (or 12:00 AM). You should change the data type of the database field into datetime, if you store the date as text you can't work with the value. WHen you display the value, you just format it the way that you want it.
--- "Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things." -- Douglas Adams
-
A DataTime value always has a date and a time component. If you don't specify the time component, it becomes zero (or 12:00 AM). You should change the data type of the database field into datetime, if you store the date as text you can't work with the value. WHen you display the value, you just format it the way that you want it.
--- "Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things." -- Douglas Adams
I have Varchar as my datatype, I checked CSV File in that Date column i found in the Format cells that the column is defined as Date. I think that may the problem , this is the code i use string ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=\"Text;HDR=No;FMT=Delimited\\\""; System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(ConStr); System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter("Select * from " + file, conn); da.Fill(ds, "TextFile"); DGCsv.DataSource = ds.Tables[0].DefaultView;