| | |
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 algorithm array asp barchart bitmap box broadcast buttons c# check checkbox client column combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development display draganddrop drawing encryption enum equation event excel file form format formbox forms formupdate function gdi+ httpwebrequest image index input install java label linux list listbox mandelbrot math mouseclick mysql networking operator packaging parse path photoshop picturebox pixelinversion post powerpacks programming radians regex remote remoting reporting richtextbox robot server sleep socket sql statistics stream string table text textbox thread time timer transform treeview update usercontrol validation visualstudio webbrowser wfa windows winforms wpf xml






