I want to store value from datatbase table to array.but when I do,exception"object eferance not set instance of object " through please review my code.
.cod Behinde
public DataSet showoption1()
{
SqlCommand cmd = new SqlCommand("select * from assessmenttest",con);
SqlDataAdapter adptr = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adptr.Fill(ds,"test");
int [] arr=new int[10];
DataTable table=ds.Tables[0];
for(int i=0;i<table.Rows.Count;i++ )
{
test.Agree[i] =Convert.ToInt32(ds.Tables[0].Rows[i]["option1"]);
}
Business logic layer class code:
public class test{
public static int[] agree;
}
Rows[i]contains the'option1'? You might want to try aforeachstatement instead on the items in a row to vcrify that you are getting what you expect.