Initializing mySqlDateTime variable?
Posted by: Scott Schulthess
Date: November 16, 2005 11:13AM

Basically the problem I'm having is that there is no way that I can find to initialize the MySql.Data.Types.MySqlDateTime variable. There is no minval or maxval or now method that you can set it to off the bat. Thus when you later set the value within a while(myReader.Read()) loop, since it's a loop variable asp.net ignores it and I get an error message telling me that the variable isn't initialize when I try to do something with it.


I can't find anyway to set the value of a MySqlDateTime variable besides using the MySqlDataReader.GetMySqlDateTime();

Suggestions are welcomed.



//This program is a test program only designed to expirment with the MySqlDateTime variable
//To see exactly how I can use it, or whether I should just use a try{} catch{} method for reading
//invalid mysql database values into a system.datetime variable

DateTime myDateTime;
MySql.Data.MySqlClient.MySqlDataReader myDataReader;
MySql.Data.Types.MySqlDateTime mySqlDateTime;
mySqlDateTime.
string myConnString = "Server=xxx;Port=xxx;Database=xxx;Uid=xxx;Pwd=xxx;Allow Zero Datetime=true;";
string myQueryString = "Select Date from database where ID=" + 1;
MySql.Data.MySqlClient.MySqlConnection myConnection = new MySql.Data.MySqlClient.MySqlConnection(myConnString);
MySql.Data.MySqlClient.MySqlCommand myCommand = new MySql.Data.MySqlClient.MySqlCommand(myQueryString, myConnection);

myConnection.Open();
myDataReader = myCommand.ExecuteReader();

while(myDataReader.Read())
{
mySqlDateTime = myDataReader.GetMySqlDateTime(0);
txtDateTime3.Text = mySqlDateTime.ToString();
}
myDateTime = System.DateTime.MaxValue;
txtDateTime2.Text = myDateTime.CompareTo(mySqlDateTime).ToString();


myDataReader.Close();
myConnection.Close();


ERROR: C:\Inetpub\wwwroot\test.aspx.cs(305): Use of unassigned local variable 'mySqlDateTime'

Options: ReplyQuote


Subject
Written By
Posted
Initializing mySqlDateTime variable?
November 16, 2005 11:13AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.