Jayita Roy

Jayita Roy

  • NA
  • 22
  • 3.5k

It's showing System.Data.DataRowView in SQL database

Jun 19 2015 7:42 AM

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.*/


Answers (2)