none
Web Part RRS feed

  • Question

  • Hi All,

     

    I have created a simple web part that retrieve data and populate it in drop down list.

     

    The code compiles fine. However, when I try to add the web part to a page, I got the following error:
     
    An unhandled exception has occurred.
    Request for the permission of type "System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToke=b77a5c56e089" failed.
     
    Any idea? Thanks in advance.

     
    here is the code


    public DataTable getRecords()
    {
    SqlConnection myConnection;
    myConnection =
    new SqlConnection(@"Server=servernam;user id=username;password=password;Database=databasename");
    SqlDataAdapter da = new SqlDataAdapter("Select VendorID, CompanyName from tblVendor", myConnection);
    DataTable dt = new DataTable("Vendor");
    da.Fill(dt);
    myConnection.Close();
    return dt;
    }
    protected override void CreateChildControls()
    {
    DropDownList ddVendors;
    ddVendors =
    new DropDownList();
    ddVendors.ID =
    "vendors";
    //ddVendors.AppendDataBoundItems = true;
    ddVendors.DataSource = getRecords();
    ddVendors.DataTextField =
    "CompanyName";
    ddVendors.DataValueField =
    "VendorID";
    ddVendors.DataBind();
    this.Controls.Add(ddVendors);
    }

    Tuesday, March 4, 2008 9:28 PM