So this is the error I am getting after working on a form that allows the user to insert some values in the table. The issue happens when I try to populate the combo boxes on the form upon the opening/Loading of the form.
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Configuration;
- using System.Data;
- using System.Data.OleDb;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
-
- namespace Call_Logger
- {
- public partial class Form2 : Form
- {
- private OleDbConnection con = new OleDbConnection();
- public Form2()
- {
- InitializeComponent();
- con.ConnectionString = ConfigurationManager.ConnectionStrings["Connection"].ToString();
- }
-
- private void btn_Save_Click(object sender, EventArgs e)
- {
- try
- {
-
- con.Open();
- OleDbCommand command = new OleDbCommand();
- command.Connection = con;
- command.CommandText = ("insert into CLTRTRN (CallNo, CallLogBy, CallLogDate, CallLogTime, CallType, CallLocation, ProblemDescription1, ProblemDescription2, IncidentNo, Caller, CallFor, AssignedBy, AssignedDate, AssignedTime, ForwardTo, ContactPerson, ForwardDate, ForwardTime, ActionTaken1, ActionTaken2, NextStep1, NextStep2, ClosedBy, CloseDate, CloseTime, Remarks1, Remarks2, Status) values ('" + txtLogBy.Text + "','" + txtLogDate.Text + "','" + txtLogTime.Text + "','" + comboBox3.Text + "','" + comboBox2.Text + "','" + txtProb1.Text + "','" + txtProb2.Text + "','" + txtIncidentNo.Text + "','" + txtCaller.Text + "','" + txtCallFor.Text + "','" + txtAssignedBy.Text + "','" + txtAssignedDate.Text + "','" + txtAssignedTime.Text + "','" + txtFwdTo.Text + "','" + txtContactPerson.Text + "','" + txtFwdDate.Text + "','" + txtFwdTime.Text + "','" + txtAction1.Text + "','" + txtAction2.Text + "','" + txtNextStep1.Text + "','" + txtNextStep2.Text + "','" + txtClosedBy.Text + "','" + txtClosedDate.Text + "','" + txtCloseTime.Text + "','" + txtRemarks1.Text + "','" + txtRemarks2.Text + "','" + comboBox1.Text + "')");
- command.ExecuteNonQuery();
-
- MessageBox.Show("Data Saved Successfully");
- con.Dispose();
- this.Hide();
- Dashboard dboard = new Dashboard();
- dboard.ShowDialog();
- con.Close();
- }
-
- catch (Exception ex)
- {
- MessageBox.Show("Error " + ex);
- }
- }
-
- private void Form2_Load(object sender, EventArgs e)
- {
- try
- {
-
- con.Open();
- OleDbCommand command = new OleDbCommand();
- command.Connection = con;
- command.CommandText = ("select * from Status");
- command.CommandText = ("select * from Location");
- command.CommandText = ("select * from CallType");
-
- OleDbDataReader reader = command.ExecuteReader();
- while (reader.Read())
- {
- comboBox1.Items.Add(reader["StatusType"].ToString());
- comboBox2.Items.Add(reader["LocationType"].ToString());
- comboBox3.Items.Add(reader["CallingType"].ToString());
- }
- con.Close();
- }
-
- catch (Exception ex)
- {
- MessageBox.Show("Error " + ex);
- }
- }
-
- private void groupBox1_Validating(object sender, CancelEventArgs e)
- {
- foreach (Control control in groupBox1.Controls)
- {
- var lst = new List<string>() { "System.Windows.Forms.TextBox", "System.Windows.Forms.ComboBox" };
- if (!lst.Contains(control.GetType().ToString(), StringComparer.OrdinalIgnoreCase)) continue;
- if (string.IsNullOrEmpty(control.Text) && string.IsNullOrEmpty(control.Text))
-
- {
- MessageBox.Show(control.Name + " Can not be empty");
- }
-
- }
- }
-
- private void groupBox3_Validating(object sender, CancelEventArgs e)
- {
- foreach (Control control in groupBox3.Controls)
- {
- var lst = new List<string>() { "System.Windows.Forms.TextBox" };
- if (!lst.Contains(control.GetType().ToString(), StringComparer.OrdinalIgnoreCase)) continue;
- if (string.IsNullOrEmpty(control.Text) && string.IsNullOrEmpty(control.Text))
- {
- MessageBox.Show(control.Name + " Can not be empty");
- }
-
- }
- }
-
- private void groupBox4_Validating(object sender, CancelEventArgs e)
- {
- foreach (Control control in groupBox4.Controls)
- {
- var lst = new List<string>() { "System.Windows.Forms.TextBox", "System.Windows.Forms.ComboBox" };
- if (!lst.Contains(control.GetType().ToString(), StringComparer.OrdinalIgnoreCase)) continue;
- if (string.IsNullOrEmpty(control.Text) && string.IsNullOrEmpty(control.Text))
- {
- MessageBox.Show(control.Name + " Can not be empty");
- }
-
- }
- }
-
- private void groupBox7_Validating(object sender, CancelEventArgs e)
- {
- foreach (Control control in groupBox7.Controls)
- {
- var lst = new List<string>() { "System.Windows.Forms.TextBox" };
- if (!lst.Contains(control.GetType().ToString(), StringComparer.OrdinalIgnoreCase)) continue;
- if (string.IsNullOrEmpty(control.Text) && string.IsNullOrEmpty(control.Text))
- {
- MessageBox.Show(control.Name + " Can not be empty");
- }
-
- }
- }
-
- private void groupBox8_Validating(object sender, CancelEventArgs e)
- {
- foreach (Control control in groupBox8.Controls)
- {
- var lst = new List<string>() { "System.Windows.Forms.TextBox", "System.Windows.Forms.ComboBox" };
- if (!lst.Contains(control.GetType().ToString(), StringComparer.OrdinalIgnoreCase)) continue;
- if (string.IsNullOrEmpty(control.Text) && string.IsNullOrEmpty(control.Text))
- {
- MessageBox.Show(control.Name + " Can not be empty");
- }
-
- }
- }
-
- private void btn_ViewRecords_Click(object sender, EventArgs e)
- {
- this.Hide();
- Dashboard dboard = new Dashboard();
- dboard.ShowDialog();
-
- }
-
-
-
-
- }
-
-
-
-
-
-
-
-
- }