2
Answers

Class Implement and Factory

Rashid Khan

Rashid Khan

15y
2.2k
1
i create a class with fill data set and i used this class in my aspx.cs page,
but for this i have to write 4 extra lines for data binding with dropdownlist.
so i want to create factory which take SP, and values and return filled dropdown list and for this it takes Dataset from FILLDS class.
here is my code for class:

public class Myclass
{
    #region Global variable declaration
    SqlConnection con;
    SqlCommand cmd;
    DataSet ds;
    SqlDataAdapter adpt;
    #endregion
 #region function filling dataset

    public DataSet FillDS (SqlConnection con, string spName, SqlParameter[] param)
    {
        if (con != null && !string.IsNullOrEmpty(spName) && param.Length > 0)
        {
           
            if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }
            cmd = new SqlCommand(spName, con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd = AddParameterInCommand(cmd, param);

            ds = new DataSet();
            adpt = new SqlDataAdapter(cmd);
            adpt.Fill(ds);

            con.Close();
            return ds;
        }
        else
        {
            return null;
        }
    }

    #endregion




    #region funtion for adding parameters in command object

    private SqlCommand AddParameterInCommand(SqlCommand cmd, SqlParameter[] param)
    {
        if (cmd != null && param.Length > 0)
        {
            foreach (SqlParameter p in param)
            {
                if (p.Value == null)
                {
                    p.Value = DBNull.Value;
                }
                cmd.Parameters.Add(p);
            }
        }
        return cmd;
    }
    #endregion

    #region funcatiom for databinding(it might be completely wrong)

    public void getDL(string spName, string Value1, string value2)
    {
        DropDownList ddl1 = new DropDownList();
        ddl1.DataSource =FillDS();(error comes in this line :No overload for method 'FillDS' takes '0' arguments)
        ddl1.DataTextField = Value1 ;
        ddl1.DataValueField = value2  ;
        ddl1.DataBind();

    }
  
    #endregion

on aspx.cs page:

public partial class ClaasImpliment : System.Web.UI.Page
{
    #region object for data function class

    Myclass objMC = new Myclass();

    #endregion
private void FillList()
    {
        //if (IsPostBack)
        //{
        SqlParameter[] param = new SqlParameter[1];
        param[0] = new SqlParameter("@deptId", SqlDbType.NChar, 20);
        param[0].Value = 0;

        DataSet ds = objMC.FillDS(objMC.Connect(), "usp_SelectDepartmentById", param);
      
            if (ds != null)
            {
                objMC.getDL("usp_SelectDepartmentById","DeptName","DeptId",ddldeptname );

   }

please check it out nd tell me where is the problem,. i m so confused so making mistakes more nd more
Thanks in adv
Answers (2)
0
Hawkmoth
NA 11 0 20y
I Have some more info. In my case I created a project using Visual Studio 2000.net and Crystal Reports V8.5 with the crystal report veiwer tool on 2 forms. I then upgraded to Visual Studio 2003.net and Crystal Reports V10 Some time later I revisited my project made some minor changes and rebuilt it. This seemed to work ok on my pc. I then installed it onto another pc and stated the program. Everything seemed ok untill i got to one of the forms that had veiwer control on it. Then I recieved the above error It appears that if you created a project using an older version of Visual Studio.net / crystal reports or one of it's tool and after updating the crystal reports. From version 9.1.3300.0 or 9.1.5000.0 to 10.0.3300.0 You then building the project and installing the resulting program onto another 'clean' pc, you may get this error System.IO.FileNotFoundException: File or assembly name CrystalDecisions.Windows.Forms, or one of its dependencies, was not found. or somthing very similar. To get around this you need to make sure your project referances the new verisons that you have upgraded to. Open your project and remove the form tools (like the crystal report viewer tool) from the forms and Toolbox. Then remove the Crystal report Referances in the Project Explorer. CrystalDecisions.CrystalReports.Engine. crystaldecisions.windows.forms CrystalDecisions.ReportSource. CrystalDecisions.Shared. Now add the new updated tools (make sure they are the correct version) to the Toolbox and redraw them onto your forms in the designer. In doing this the new Crystal report referances should automatical appear in the Project Explorer. That takes care of the project itself but you will also need to download the merge modules that matches your version of crystal reposts and include these in the setup package. This is most important as the Client pc will not have the correct dlls. Do not assume that just because you have the new Crystal Reports installed that the merge modules will also be upgraded. They Don't here is a usful link to the merge modules. http://support.businessobjects.com/fix/merge_modules.asp
0
Hawkmoth
NA 11 0 20y
I have a similar error after upgrading from visual studio 2000.net to 2003.net. I also upgraded crystal reports version 10 Developer. You may also wish to take a look at this. http://support.businessobjects.com/library/kbase/articles/c2013897.asp Hawkmoth
0
tuortoam
NA 12 0 21y
For those interested: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/crystlmn/html/crcondeployingcrystalreportsinnetapplications.asp Problem solved?? (we'll see) -Ant