| | |
Insert to DB (Access)
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
Hi,
I am trying to insert into Access Database using following code
all the columns get inserted apart from employee and employee in access db is numeric and optional. can someone help please.
thanks
I am trying to insert into Access Database using following code
C# Syntax (Toggle Plain Text)
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
![]() |
Similar Threads
- Insert newline character in to Access databse (MS Access and FileMaker Pro)
- VB 2008 INSERT into MS Access Error (VB.NET)
- Parse String for RSS feed and Iterate to get lottery numbers (ASP.NET)
- Connecting 2 connection using MySql and access (Visual Basic 4 / 5 / 6)
- Bulk Insert/update in Access (Visual Basic 4 / 5 / 6)
- insert data to Access (ASP)
- No Error, No Insert: ASP to Access (ASP)
Other Threads in the C# Forum
- Previous Thread: How Insert Data Using EntityDataSource in FormView
- Next Thread: string manipulations
| Thread Tools | Search this Thread |
.net access ado.net algorithm array backup barchart bitmap box broadcast buttons c# check checkbox client color combobox control conversion csharp custom database datagrid datagridview dataset datetime decryption degrees development draganddrop drawing encryption enum event excel file files form format forms function gdi+ httpwebrequest i18n image imageprocessing index input install java label list listbox listener mandelbrot math mouseclick mysql operator path photoshop picturebox pixelinversion post programming radians regex remote remoting richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer update uploadatextfile usercontrol users validation view visualstudio webbrowser whileloop windows winforms wpf xml






