15,905,508 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by tnewt (Top 8 by date)
tnewt
18-Jan-16 11:38am
View
Got it!
cmd.Parameters.AddWithValue("@IFIELD4", String.Format("{0:MM/dd/yyyy}", dataTable.Rows[i][4]));
You rock PIEBALDconsult! Thank you!
you made me do it and i learned alot from it.
Cleaning up the code and i will post it later today.
tnewt
18-Jan-16 10:28am
View
the csv file value is "06/08/1994"
string test1 = dataTable.Rows[i].ItemArray.GetValue(4).ToString();
string test2 = String.Format("{0:MM/dd/yyyy}", dataTable.Rows[i].ItemArray.GetValue(4).ToString());
returns "6/8/1994 12:00:00 AM" before sending the value to the mdb file
tnewt
18-Jan-16 9:46am
View
Yes it is working. i had to move some of the code within the for each row loop because it was only updating the first line. I will post the finished code when it is complete. I have one last issue if you can guide me.
cmd.Parameters.AddWithValue("@IFIELD7", dataTable.Rows[i][7]);
cmd.Parameters.AddWithValue("@IFIELD7", dataTable.Rows[i].ItemArray.GetValue(7));
both return the value(in the mdb)in the format of "1994-06-08 00:00:00"
cmd.Parameters.AddWithValue("@IFIELD7", dataTable.Rows[i].ItemArray.GetValue(7).ToString());
returns the format "6/8/1994 12:00:00 AM"
the value in the csv file and the desired value in the mdb should be "06/08/1994"
the field format in the mdb file is set to date mm/dd/yyyy only.
is there a way to achive the correct format?
tnewt
17-Jan-16 22:11pm
View
yes IDNUM is an int.
I tried all of the below and did not get an error but it also did not update the mdb file.
cmd.Parameters.AddWithValue("@IFIELD7", dataTable.Rows[i][7]);
cmd.Parameters.AddWithValue("@IDNUM", dataTable.Rows[i][0]);
cmd.Parameters.AddWithValue("@IFIELD7", dataTable.Rows[i].ItemArray.GetValue(7));
cmd.Parameters.AddWithValue("@IDNUM", dataTable.Rows[i].ItemArray.GetValue(0));
cmd.Parameters.AddWithValue("@IFIELD7", dataTable.Rows[i].ItemArray.GetValue(7).ToString());
cmd.Parameters.AddWithValue("@IDNUM", dataTable.Rows[i].ItemArray.GetValue(0).ToString());
and I checked I am getting the correct values with dataTable.Rows[i].ItemArray.GetValue(0).ToString()
learning a lot... thanks so much for your help
tnewt
17-Jan-16 21:29pm
View
Got this far but now I get a 'System.InvalidCastException'
do I need to match the type I am reading or the type in the mdb file?
cmd.CommandText = "UPDATE INDEXDB1 SET IFIELD1= @IFIELD1, IFIELD2 = @IFIELD2, IFIELD3 = @IFIELD3, IFIELD4= @IFIELD4, IFIELD5 = @IFIELD5, IFIELD6 = @IFIELD6, IFIELD7 = @IFIELD7 WHERE IDNUM= @IDNUM";
cmd.Parameters.Add(new SqlParameter("@IDNUM", CommandType.Text).Value = dataTable.Rows[i].ItemArray.GetValue(0).ToString());
cmd.Parameters.Add(new SqlParameter("@IFIELD1", CommandType.Text).Value = dataTable.Rows[i].ItemArray.GetValue(1).ToString());
cmd.Parameters.Add(new SqlParameter("@IFIELD2", SqlDbType.VarChar).Value = dataTable.Rows[i].ItemArray.GetValue(2).ToString());
cmd.Parameters.Add(new SqlParameter("@IFIELD3", SqlDbType.VarChar).Value = dataTable.Rows[i].ItemArray.GetValue(3).ToString());
cmd.Parameters.Add(new SqlParameter("@IFIELD4", SqlDbType.VarChar).Value = dataTable.Rows[i].ItemArray.GetValue(4).ToString());
cmd.Parameters.Add(new SqlParameter("@IFIELD5", SqlDbType.VarChar).Value = dataTable.Rows[i].ItemArray.GetValue(5).ToString());
cmd.Parameters.Add(new SqlParameter("@IFIELD6", SqlDbType.VarChar).Value = dataTable.Rows[i].ItemArray.GetValue(6).ToString());
cmd.Parameters.Add(new SqlParameter("@IFIELD7", SqlDbType.VarChar).Value = dataTable.Rows[i].ItemArray.GetValue(7).ToString());
tnewt
17-Jan-16 16:47pm
View
cool. taking some time but reading up and trying to understand parameterized statements.
tnewt
17-Jan-16 14:55pm
View
Thank you for pointing me in the right direction. I need to do more reading up on the link. not working but I tried:
cmd.CommandText = "UPDATE INDEXDB1 SET IFIELD1='dataTable.Rows[i].ItemArray.GetValue(1)',IFIELD2='dataTable.Rows[i].ItemArray.GetValue(2)',IFIELD3='dataTable.Rows[i].ItemArray.GetValue(3)',IFIELD4='dataTable.Rows[i].ItemArray.GetValue(4)',IFIELD5='dataTable.Rows[i].ItemArray.GetValue(5)',IFIELD6='dataTable.Rows[i].ItemArray.GetValue(6)',IFIELD7='dataTable.Rows[i].ItemArray.GetValue(7) WHERE IDNUM='dataTable.Rows[i].ItemArray.GetValue(0)'";
tnewt
17-Jan-16 14:54pm
View
Deleted
Thank you for pointing me in the right direction. I need to do more reading up on the link. not working but I tried:
Hide Copy Code
cmd.CommandText = "UPDATE INDEXDB1 SET IFIELD1='dataTable.Rows[i].ItemArray.GetValue(1)',IFIELD2='dataTable.Rows[i].ItemArray.GetValue(2)',IFIELD3='dataTable.Rows[i].ItemArray.GetValue(3)',IFIELD4='dataTable.Rows[i].ItemArray.GetValue(4)',IFIELD5='dataTable.Rows[i].ItemArray.GetValue(5)',IFIELD6='dataTable.Rows[i].ItemArray.GetValue(6)',IFIELD7='dataTable.Rows[i].ItemArray.GetValue(7) WHERE IDNUM='dataTable.Rows[i].ItemArray.GetValue(0)'";
Show More