Hi,
I am trying to insert into Access Database using following code
OleDbConnection empConnection = connection;
string insertStatement = "INSERT INTO d "
+ "([Employee],[Deduction Type],[Number of Hours],[value],[Month],[Year],[Comment]) "
+ "VALUES (@Employee,@DeductionType,@NumberofHours,@value,@Month,@Year,@Comment)";
command = new OleDbCommand(insertStatement, empConnection);
command.Parameters.Add("Employee", OleDbType.Numeric).Value = Convert.ToInt16(txtID.Text);
command.Parameters.Add("DeductionType", OleDbType.Numeric).Value = Convert.ToInt16(cmbDedNum.Text);
if (txtNoOfHours.Text == string.Empty) { txtNoOfHours.Text = "1"; }
command.Parameters.Add("NumberofHours", OleDbType.Numeric).Value = Convert.ToInt16(txtNoOfHours.Text);
if (txtValue.Text == string.Empty) { txtValue.Text = "0"; }
command.Parameters.Add("value", OleDbType.Numeric).Value = Convert.ToInt16(txtValue.Text);
if (cmbMonth.Text == string.Empty) { cmbMonth.Text = ""; }
command.Parameters.Add("Month", OleDbType.VarChar).Value = cmbMonth.Text;
if (cmbYear.Text == string.Empty) { cmbYear.Text = ""; }
command.Parameters.Add("Year", OleDbType.VarChar).Value = cmbYear.Text;
if (txtComments.Text == string.Empty) { txtComments.Text = ""; }
command.Parameters.Add("Comment", OleDbType.VarChar).Value = txtComments.Text;
if (cmbYear.Text == string.Empty || cmbMonth.Text == string.Empty || txtComments.Text == string.Empty)
{
MessageBox.Show("Complete Year/Month/Comments Fields");
return;
}
empConnection.Open();
try
{
int count = command.ExecuteNonQuery();
all the columns get inserted apart from employee and employee in access db is numeric and optional. can someone help please.
thanks