private void button_Pass_Click(object sender, EventArgs e)
{
SqlConnection con1 = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=db-ub;Integrated Security=True");
SqlCommand cmd1 = new SqlCommand("Insert into Visitors(To_Whom) values (@whom)", con1);
con1.Open();
int o = cmd1.ExecuteNonQuery();
MessageBox.Show(o + " :Record has been inserted");
}
private void Form3_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=db-ub;Integrated Security=True");
con.Open();
SqlCommand sc = new SqlCommand("select Employee_Name from Employees", con);
SqlDataReader reader;
reader = sc.ExecuteReader();
DataTable dt = new DataTable();
dt.Columns.Add("Employee_Name", typeof(string));
dt.Load(reader);
comboBox_TOWHOM.DataSource = dt;
comboBox_TOWHOM.DisplayMember = "Employee_Name";
con.Close();
}
/*I have two tables “Visitors” and “Employees”, I have Employee_Name. In my form3 there is a combobox which is fetching data from the “Employees” table and storing it to the “Visitors” table. Everything is fine but in the “Visitors” table it’s showing “System.Data.DataRowView” under To_Whom column. Please help.*/