Solved

ODBCCommand & DateTime

Posted on 2006-11-21
7
1,898 Views
Last Modified: 2008-01-09
Hi,

I have two problems with my code...
1. about DateTime, when I acquire a DateTime, it contains AM/PM in my native language, which MySQL cannot understands.  How can I solve this problem?
2. I try to add attributes into SQL commands, but I got this error message "invalid attributes".  How exactly I can pass the correct values in parameters?

Here is my code..
========================
OdbcCommand dc;
OdbcConnection conn;

using (conn = new OdbcConnection(@"Driver={MySQL Connector/ODBC v5 Driver};SEVER=localhost;UID=root;PWD=root;Database=reporter;"))
 {
     string user_id = obj.user_id;
     DateTime date = obj.date;

     dc = conn.CreateCommand();
     conn.Open();
     dc.CommandText = "use reporter;";
     dc.ExecuteNonQuery();


     dc = new OdbcCommand("insert into rpt_carrier_id (user_id, date) " +
         "values (?, ?)", conn);
     dc.Parameters.Add("", OdbcType.VarChar, 32).Value = user_id;
     dc.Parameters.Add("", OdbcType.DateTime).Value = date;

     dc.ExecuteNonQuery();
}
0
Comment
Question by:xenia27
  • 4
  • 3
7 Comments
 

Author Comment

by:xenia27
ID: 17993702
Is there anyway that AM/PM won't be shown???
0
 
LVL 8

Expert Comment

by:Razzie_
ID: 17993800
Hi xenia,

1. You could manually format the date to whichever format you want. For example, you can use date.ToString("MM-dd-yyyy") to get your date in a 11-22-2006 format, and add the date as a string parameter.

2. You should name the sql parameters:

dc = new OdbcCommand("insert into rpt_carrier_id (user_id, date) values (@id, @date)", conn);
dc.Parameters.Add("@id", OdbcType.VarChar, 32).Value = user_id;
dc.Parameters.Add("@date", OdbcType.DateTime).Value = date;

HTH,
Razzie
0
 

Author Comment

by:xenia27
ID: 17993809
I am still having this error code.."ERROR [HY092][MySQL][MyODBC 5.00.05] Invalid attribute/option identifier"
I am using ODBCcommand to set the parameters.  Do I still use the same way to set the parameters?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 8

Expert Comment

by:Razzie_
ID: 17994301
Hmm well I'm not sure about this. I always use the Mysql .NET driver instead of ODBC (http://dev.mysql.com/downloads/connector/net/1.0.html) since it is mysql specific. You can always give it a try if you want. It is easy. Just install it, reference the .dll in your VS.NET project, and you can use it.

Anyway, to answer your question, I'm not sure about the parameter syntax. Try:

dc = new OdbcCommand("insert into rpt_carrier_id (user_id, date) values (?, ?)", conn);
dc.Parameters.Add("@user_id", OdbcType.VarChar, 32);
dc.Parameters["@user_id"].Value = user_id;
dc.Parameters.Add("@date", OdbcType.DateTime);
dc.Parameters["@date"].Value = date;

You can give it a try. Sorry I can't test it for you, but do not have a mysql database with ODBC connector here to test it for you!
HTH,
Razzie
0
 

Author Comment

by:xenia27
ID: 17994312
I still have  that error message...What exactly it means "Invalid attribute" or "Invalid option identifier"??  I do believe all my attributes are correct...
0
 
LVL 8

Accepted Solution

by:
Razzie_ earned 500 total points
ID: 17994929
Well after searching the net for this, it seems this is a problem with MDAC / ODBC. Some few links with info about this:

http://groups.google.com/group/microsoft.public.sqlserver.connect/msg/b1b1c54950503bdf?hl=en&lr=&ie=UTF-8
http://www.webservertalk.com/message1201947.html

I really hope this helps. Try reinstalling ODBC / MDAC drivers.

Good luck,
Razzie
0
 

Author Comment

by:xenia27
ID: 18005384
OK...that's why I cannot run the code...thank you~~~
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now