I have created windows application, and i use C# code. in this , call a readdbdata method whose return type is structure. and i want to assign this returned value to the structure array.
{
acccode = 120101000001; widget = 1;
result = ebis.ReadData(conn, acccode);
for (int i = 0; i < result.Count; i++)
{
UserProfile details = (UserProfile)result[i];
details.metric[i] = ebis.ReadDBData(conn, details.usercode, "120101000001");//here an error is showing "An unhandled exception of type 'System.NullReferenceException' occurred in eBis Application.exe
"
}
}
//this are the code in main application. the following code is ReadDBData
public Metric ReadDBData(MySqlConnection connection, string usercode, string accode)
{
int count = 0;
ArrayList userDataList = new ArrayList();
Metric[] usermetric;
command = new MySqlCommand("SELECT SUM(d.amt) Amount, MAX(d.CREATED_DATE) createddate, MAX(d.MODIFIED_DATE) modifieddate FROM ddata d, branchuser b, userprofile p WHERE d.acccode = '" + accode + "' AND d.br = b.BRCODE AND b.USERCODE = p.CODE AND cancel = 'No' and b.USERCODE='" + usercode + "' GROUP BY b.USERCODE;", connection);
adapter = new MySqlDataAdapter(command);
adapter.Fill(dt);
int i;
count = dt.Rows.Count;
usermetric = new eBisExtension.Metric[count];
for (i = 0; i < dt.Rows.Count; i++)
{
usermetric[i] = new Metric
{
code = accode,
amount = Convert.ToDouble(dt.Rows[i]["Amount"].ToString()),
amountstring = Convert.ToString("{\"value\":" + dt.Rows[i]["Amount"].ToString() + "}")
};
return usermetric[i];
}
}
structures in my class
public struct Metric
{
public string code;
public double amount;
public string amountstring;
};
public struct UserProfile
{
public string usercode;
public string name;
public string group;
public string password;
public string email;
public Metric[] metric;
};
Plz help me..i wanted to complete this project as early as possible.