object reference error comes when your object is null
here is your ds.Tables["EMPLOYEE"] is null becouse you not fill it
when you created dataset
you also have to create sqldataadapter to fill the dataset and fill time set the name of table i.e
SqlDataAdapter da = new SqlDataAdapter(cmd);
System.Data.DataSet ds = new System.Data.DataSet("emp");
da.Fill(ds,"EMPLOYEE");
string nameslist = string.Empty;
foreach (DataRow dr in ds.Tables["EMPLOYEE"].Rows)
{
nameslist += dr["ENAME"];
}
test code is here
try
{
System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(@"Data Source=My\SQLEXPRESS;Initial Catalog=Test;Integrated Security=true;");
con.Open();
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandText = "select * from EMPLOYEE";
cmd.Connection = con;
employee emp= new employee();
SqlDataAdapter da = new SqlDataAdapter(cmd);
System.Data.DataSet ds = new System.Data.DataSet("emp");
da.Fill(ds,"EMPLOYEE");
string nameslist = string.Empty;
foreach (DataRow dr in ds.Tables["EMPLOYEE"].Rows)
{
nameslist += dr["ENAME"];
}
}
catch (Exception ex)
{ throw ex;}
happy coding :) :) :)