views:

207

answers:

2

im trying to insert data into my oracle database but i am getting "invalid month" error as it seems that i cant convert the datetimepicker value of my form into oracle date or timestamp(7) please help!

my code

dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = " dd MM yyyy  ";
string m = "insert into member(memberid,name,street,roadno,houseno,phoneno,joindate,sex) values(member_deptno.nextval,'" + a + "','" + b+ "','" + c + "','" + d + "','" + h + "','" + dateTimePicker1.Value.Date+ "','"+de+"')";
+2  A: 

user parameterized sql insert.

e.g. parameterized select query

SqlConnection objConnection = new SqlConnection(connectionString);
objConnection.Open();
SqlCommand objCommand = new SqlCommand(
   "SELECT * FROM User WHERE Name = @Name AND Password = @Password",
   objConnection);
objCommand.Parameters.Add("@Name", tbName.Text);
objCommand.Parameters.Add("@Password", tbPassword.Text);
SqlDataReader objReader = objCommand.ExecuteReader();
Saar
He's using Oracle, not SQL Server.
SLaks
@SLaks: I know, I have just give an example.
Saar
+1  A: 

As others have mentioned parameters are the way to go but I don't think they'll solve your issue.

I assume the CustomFormat shown in your snippet is the format Oracle wants. The problem is that when you call dateTimePicker1.Value.Date it gives you a DateTime object and since you're combining it with a string it executes the .ToString() method which results in a different format. You should put your format string in the .ToString() to control the output. Example:

dateTimePicker1.Value.Date.ToString("dd MM yyyy");
Cory Charlton