Hey all I currently am having trouble utilizing the oledbcommand method named parameter because I do not know how to use it properly :(
Here is my class:
namespace CalendarApplicationLibrary
{
public class MeetingEntryDA
{
private const string CONNECTION_STRING =
@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Entry\entry.accdb;Persist Security Info=False;";
public void WriteDataToFile(MeetingEntry currentEntry)
{
OleDbConnection dbConnection = new OleDbConnection(CONNECTION_STRING);
string commandString =
"INSERT INTO MeetingEntries (Subject, Location, Start Date, End Date, Enable Alarm, Repeat Alarm, Reminder, Repetition Type)" + " VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
OleDbCommand commandStatement = new OleDbCommand(commandString, dbConnection);
commandStatement.Parameters.Add("@Subject", OleDbType.VarWChar, 30).Value = currentEntry.Subject;
commandStatement.Parameters.Add("@Location", OleDbType.VarWChar, 50).Value = currentEntry.Location;
commandStatement.Parameters.Add("@Start Date", OleDbType.Date, 40).Value = currentEntry.StartDateTime.Date;
commandStatement.Parameters.Add("@End Date", OleDbType.Date, 40).Value = currentEntry.EndDateTime.Date;
commandStatement.Parameters.Add("@Enable Alarm", OleDbType.Boolean, 1).Value = currentEntry.IsAlarmEnabled;
commandStatement.Parameters.Add("@Repeat Alarm", OleDbType.Boolean, 1).Value = currentEntry.IsAlarmRepeated;
commandStatement.Parameters.Add("@Reminder", OleDbType.Integer, 2).Value = currentEntry.Reminder;
commandStatement.Parameters.Add("@Repetition Type", OleDbType.VarWChar, 10).Value = currentEntry.Repetition;
dbConnection.Open();
commandStatement.ExecuteNonQuery();
}
}
}
What I am having trouble is that I am always getting a insert into error when the time comes that I have to run the insert statement. I am most certain that the culprit for this is those pesky datetimepicker values. I guess I am casting incorrectly that's why it won't insert properly in my database.
My properties for each column in my ms access database are as follows:
Subject - type text
Location - type text
Start Date - type Date/Time, short date format
End Date - type Date/Time, short date format
Enable Alarm - type Yes/No, Format true/false
Repeat Alarm - type Yes/No, Format true/false
Reminder - type number
Repetition Type - type text
Please show me how to properly format my values so that I may correctly cast them into my insert statement. Thank you!
EDIT:
Oh and my repetition type thingy there is of type enum, will I have to convert it to string when I place it on my statement? I am assuming that it is automatically cast as a string though. That maybe another point where I am incorrectly casting. MY IsEnabledAlarm and IsAlarmRepeated are from checkbox controls so I am certain that they return boolean values. I am just not so sure with my repetiton type, start date and end date values.