Solved

ODBCCommand & DateTime

Posted on 2006-11-21
7
1,906 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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, f…

910 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

21 Experts available now in Live!

Get 1:1 Help Now