Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
public RolesProperties[] getDAta(RolesProperties OP)
        {
            string sqlstring = "";
            sqlstring = "select Id,user_role,details";
            sqlstring += "where 1=1";

            if (OP.ID != "") { sqlstring += "and Id=" + SqlFunctions.qt(OP.ID); }
            if (OP.USER_ROLE != "") { sqlstring += "and user_role" + SqlFunctions.qt(OP.USER_ROLE); }
            if (OP.ROLE_DETAILS != "") { sqlstring += "and details" + SqlFunctions.qt(OP.ROLE_DETAILS); }

            RolesProperties[] omain;
            SqlDataReader drx;
            dbDataReader dr = new dbDataReader();
            dr.ConnectionName = "ConnectionString";
            dr.SqlString = sqlstring;
            drx = dr.GetData();
            int cnt = 0;
            if (drx != null)
            {
                if (drx.HasRows)
                {
                    while (drx.Read())
                    {
                        RolesProperties oTmp = new RolesProperties();
                        oTmp.ID = (string)SqlFunctions.Nz(drx["Id"], "");
                        oTmp.USER_ROLE = (string)SqlFunctions.Nz(drx["user_role"], "");
                        oTmp.ROLE_DETAILS = (string)SqlFunctions.Nz(drx["details"], "");

                        //Array.Resize(ref omain, cnt + 1);
                        //omain[cnt] = oTmp;
                        //cnt += 1;

                        //if (omain != null)
                        //    Array.Copy(omain, temp, Math.Min(omain.Length, temp.Length));
                        //omain = temp;
                
                        
                    }
                }
                drx.Close();
                drx = null;
                dr = null;
            }
            return omain;
        }

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 27-Jun-15 0:35am
v2

1 solution

The simplest solution is not to use an array - use a List<RolesProperties> instead and it will expand for you. Then return the List with ToArray()
 
Share this answer
 
Comments
Atmesh 27-Jun-15 6:39am    
thank you..Will you please explain briefly
OriginalGriff 27-Jun-15 6:52am    
You know how to use a List, surely?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900