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=, 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");
    return dt;
    protected override void CreateChildControls()
    DropDownList ddVendors;
    ddVendors =
    new DropDownList();
    ddVendors.ID =
    //ddVendors.AppendDataBoundItems = true;
    ddVendors.DataSource = getRecords();
    ddVendors.DataTextField =
    ddVendors.DataValueField =

    Tuesday, March 4, 2008 9:28 PM