المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Convert .Net datatype to Mysql datatype



C# Programming
05-07-2009, 02:22 AM
Hi people,

I have the a form in my application where the user can enter a data and time and then save it to a Mysql database. but I get a FormatExeption saying "Input string was not in a correct format" How can I convert from .net datatime datatype to Mysql database type ?

Heres my method for inserting a row that contains a datetime datatype
private void shiftInsertNewRow()
{
conn = new MySqlConnection
("datasource=localhost;username=admin;password=student;database=hospital");
conn.Open();


MySqlCommand command = new MySqlCommand
("insert into shifts(ShiftID, Starttime, Endtime, WardID, NurseID) select ?ShiftID, ?Starttime, ?Endtime, ?WardID, ?NurseID", conn);

command.Parameters.Add(new MySqlParameter("?ShiftID", MySqlDbType.Int32));
command.Parameters.Add(new MySqlParameter("?Starttime", MySqlDbType.Datetime));
command.Parameters.Add(new MySqlParameter("?Endtime", MySqlDbType.Datetime));
command.Parameters.Add(new MySqlParameter("?WardID", MySqlDbType.Int32));
command.Parameters.Add(new MySqlParameter("?NurseID", MySqlDbType.Int32));


command.Parameters[0].Value = shiftidTextBox.Text;
command.Parameters[1].Value = startTimeTextBox.Text;
command.Parameters[2].Value = endTimTextBox.Text;
command.Parameters[3].Value = wardShiftidTextBox.Text;
command.Parameters[4].Value = wardNameTextBox.Text;

command.ExecuteNonQuery();

conn.Close();
}

any help would be greatly appreciated http://www.barakasoft.com/script/Forums/Images/smiley_smile.gif