Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Database connection

  Asked By: Maulik    Date: Feb 25    Category: Sharepoint    Views: 636

I have created a web part and it is working fine when i include
controls that are not data driven

and i have included the following code for acessing the database

SqlConnection conn = new SqlConnection("User
ID=sa;Password=sqlsps005;Initial Catalog=Northwind;Data
Source=ETISPS005;Persist Security Info=False;");
SqlDataAdapter sda = new SqlDataAdapter("select * from
DataSet ds = new DataSet();

DataGrid dg = new DataGrid();

dg.DataSource = ds;



the piece of code is working fine seperately

but when i include that in my web part page it is not giving the

can anyone please give solution



2 Answers Found

Answer #1    Answered By: Genevieve Sherman     Answered On: Feb 25

Are you certain that you have done all the necessary configuration for Code
Access Security? This is described in the SDK...

Answer #2    Answered By: Sameera Shettar     Answered On: Feb 25

Chances are the control is not created  when data  binding is occurring
for the page. If this code  is placed in the CreateChildControls method,
try calling EnsureChildControls() during the overridden OnLoad method of
the web  part.

Didn't find what you were looking for? Find more on Database connection Or get search suggestion and latest updates.