Showing posts with label control. Show all posts
Showing posts with label control. Show all posts

Sunday, February 19, 2012

Connecting Datasource to SQL Server 7 database

Hi

I've been using the new features with ASP.Net 2 for some months now. I use the gridview control a lot with the sqldatasource. I recently started a new job and am having problems connecting a sqldatasource control to a sql server 7 database. At my old job we used sql server 2000.

I get the error: "SQL server version needs be 2000 or higher" when I try to set up a new connection.. I read some documentation that said you can use asp.net 2 datasource controls with sql server 7. Does anyone know how to get round this issue. I don't want to have to go back to 1.x methods of connecting data controls to databases using code.Crying

Thanks

As far as I know you will not be able to use the VS 2005 features from the UI with sql server 7

Friday, February 17, 2012

Connecting and Getting data from 8 tables in one sql statement

Hi everybody,

I like to get data from 8 tables to be loaded in a dropdownlist or combobox control. Desired Result is need to be filtered by Region, Company, ProjectOffice, Country, and Location and still get all rows from 3 tables after applying filters. How can this be done in one single sql statement?

I have 3 separate sql statements which needed to be only one.

Select C.CompanyID, C.[Name] As 'Company', P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID,
R.[Name] As 'Region'
From ProjectCompany E Left Join ProjectOffice P On E.ProjectOfficeID = P.ProjectOfficeID
Left Join Company C On E.CompanyID = C.CompanyID
Left Join Region R On P.RegionID = R.RegionID Order By E.ProjectOfficeID

Select P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID, R.[Name] As 'Region',
C.CountryID, C.[Name] As 'Country'
From ProjectOfficeCountry O Left Join ProjectOffice P On O.ProjectOfficeID = P.ProjectOfficeID
Left Join Country C On O.CountryID = C.CountryID
Left Join Region R On P.RegionID = R.RegionID

Select P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID, R.[Name] As 'Region',
W.LocationID, W.[Name] As 'Location'
From ProjectOfficeLocation L Left Join ProjectOffice P On L.ProjectOfficeID = P.ProjectOfficeID
Left Join Location W On L.LocationID = W.LocationID
Left Join Region R On P.RegionID = R.RegionID

Table structures (some columns)

Region table
RegionID Name

ProjectOffice table

ProjectOfficeID Name RegionID

Location Table

LocationID Name

Country table

CountryID Name

Company table

CompanyID Name

ProjectCompany table (All rows)

ID ProjectOfficeID CompanyID


ProjectOfficeCountry table (All rows)

ID ProjectOfficeID CountryID


ProjectOfficeLocation table (All rows)

ID ProjectOfficeID LocationID

maybe something like this ?

Select 'A' as [type], C.CompanyID, C.[Name] As 'Company', P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID,
R.[Name] As 'Region'
From ProjectCompany E Left Join ProjectOffice P On E.ProjectOfficeID = P.ProjectOfficeID
Left Join Company C On E.CompanyID = C.CompanyID
Left Join Region R On P.RegionID = R.RegionID Order By E.ProjectOfficeID

UNION ALL

Select 'B' as [type], P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID, R.[Name] As 'Region',
C.CountryID, C.[Name] As 'Country'
From ProjectOfficeCountry O Left Join ProjectOffice P On O.ProjectOfficeID = P.ProjectOfficeID
Left Join Country C On O.CountryID = C.CountryID
Left Join Region R On P.RegionID = R.RegionID

UNION ALL

Select 'C' as [type], P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID, R.[Name] As 'Region',
W.LocationID, W.[Name] As 'Location'
From ProjectOfficeLocation L Left Join ProjectOffice P On L.ProjectOfficeID = P.ProjectOfficeID
Left Join Location W On L.LocationID = W.LocationID
Left Join Region R On P.RegionID = R.RegionID

|||

Thanks carlop for replying,

If I did that then I could not differentiate between CompanyID and ProjectID or Company From Project Office or Location From Region, there should be a better way to do this...

Thanks.

|||

I really don’t understand why you need in single SQL Statement. Are you trying to fetch those result in single batch (single hit to server).

If you don’t use the union all then you have to use the JOIN. It may lead your (desired) result set to duplicates (for region & country) and it is not helpful on Combobox binding.

|||

ManiD,

Trying to get say data for Company, filtered by Region,Country, ProjectOffice, Company and Location, then data will be used to fill the combobox or dropdownlist control.

|||

are you like to hit the db server once to get those data.

or

you need to have all the data in columns..?

|||

ManiD,

Well, that is ideal to get all columns I needed and without duplicates. I have used several sql statements to achive same result, I wonder if it can be done using one single sql statement.

|||

While I agree with the other posters that this is not a very good idea, you could probably use union to put all of the data in a single result:

Select C.CompanyID, C.[Name] As 'Company', P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID,
R.[Name] As 'Region', 'PURPOSE1' as purpose
From ProjectCompany E Left Join ProjectOffice P On E.ProjectOfficeID = P.ProjectOfficeID
Left Join Company C On E.CompanyID = C.CompanyID
Left Join Region R On P.RegionID = R.RegionID

UNION ALL

Select P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID, R.[Name] As 'Region',
C.CountryID, C.[Name] As 'Country', 'PURPOSE2' as purpose
From ProjectOfficeCountry O Left Join ProjectOffice P On O.ProjectOfficeID = P.ProjectOfficeID
Left Join Country C On O.CountryID = C.CountryID
Left Join Region R On P.RegionID = R.RegionID

Note that you would also need to genericize the other names, like the id, the name, etc. I almost feel wrong in suggesting this, because it seems so much cleaner to make N result sets and get the data one set at a time (much cleaner and certainly eaiser to implement.)

|||

Thanks for the reply Louis.

It seems there is no exact way getting all data needed in just one sql statement. I would stick to using multiple sql statements in getting the results.

Thanks.

I think the issue in this thread is closed.

Connecting and Getting data from 8 tables in one sql statement

Hi everybody,

I like to get data from 8 tables to be loaded in a dropdownlist or combobox control. Desired Result is need to be filtered by Region, Company, ProjectOffice, Country, and Location and still get all rows from 3 tables after applying filters. How can this be done in one single sql statement?

I have 3 separate sql statements which needed to be only one.

Select C.CompanyID, C.[Name] As 'Company', P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID,
R.[Name] As 'Region'
From ProjectCompany E Left Join ProjectOffice P On E.ProjectOfficeID = P.ProjectOfficeID
Left Join Company C On E.CompanyID = C.CompanyID
Left Join Region R On P.RegionID = R.RegionID Order By E.ProjectOfficeID

Select P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID, R.[Name] As 'Region',
C.CountryID, C.[Name] As 'Country'
From ProjectOfficeCountry O Left Join ProjectOffice P On O.ProjectOfficeID = P.ProjectOfficeID
Left Join Country C On O.CountryID = C.CountryID
Left Join Region R On P.RegionID = R.RegionID

Select P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID, R.[Name] As 'Region',
W.LocationID, W.[Name] As 'Location'
From ProjectOfficeLocation L Left Join ProjectOffice P On L.ProjectOfficeID = P.ProjectOfficeID
Left Join Location W On L.LocationID = W.LocationID
Left Join Region R On P.RegionID = R.RegionID

Table structures (some columns)

Region table
RegionID Name

ProjectOffice table

ProjectOfficeID Name RegionID

Location Table

LocationID Name

Country table

CountryID Name

Company table

CompanyID Name

ProjectCompany table (All rows)

ID ProjectOfficeID CompanyID


ProjectOfficeCountry table (All rows)

ID ProjectOfficeID CountryID


ProjectOfficeLocation table (All rows)

ID ProjectOfficeID LocationID

maybe something like this ?

Select 'A' as [type], C.CompanyID, C.[Name] As 'Company', P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID,
R.[Name] As 'Region'
From ProjectCompany E Left Join ProjectOffice P On E.ProjectOfficeID = P.ProjectOfficeID
Left Join Company C On E.CompanyID = C.CompanyID
Left Join Region R On P.RegionID = R.RegionID Order By E.ProjectOfficeID

UNION ALL

Select 'B' as [type], P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID, R.[Name] As 'Region',
C.CountryID, C.[Name] As 'Country'
From ProjectOfficeCountry O Left Join ProjectOffice P On O.ProjectOfficeID = P.ProjectOfficeID
Left Join Country C On O.CountryID = C.CountryID
Left Join Region R On P.RegionID = R.RegionID

UNION ALL

Select 'C' as [type], P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID, R.[Name] As 'Region',
W.LocationID, W.[Name] As 'Location'
From ProjectOfficeLocation L Left Join ProjectOffice P On L.ProjectOfficeID = P.ProjectOfficeID
Left Join Location W On L.LocationID = W.LocationID
Left Join Region R On P.RegionID = R.RegionID

|||

Thanks carlop for replying,

If I did that then I could not differentiate between CompanyID and ProjectID or Company From Project Office or Location From Region, there should be a better way to do this...

Thanks.

|||

I really don’t understand why you need in single SQL Statement. Are you trying to fetch those result in single batch (single hit to server).

If you don’t use the union all then you have to use the JOIN. It may lead your (desired) result set to duplicates (for region & country) and it is not helpful on Combobox binding.

|||

ManiD,

Trying to get say data for Company, filtered by Region,Country, ProjectOffice, Company and Location, then data will be used to fill the combobox or dropdownlist control.

|||

are you like to hit the db server once to get those data.

or

you need to have all the data in columns..?

|||

ManiD,

Well, that is ideal to get all columns I needed and without duplicates. I have used several sql statements to achive same result, I wonder if it can be done using one single sql statement.

|||

While I agree with the other posters that this is not a very good idea, you could probably use union to put all of the data in a single result:

Select C.CompanyID, C.[Name] As 'Company', P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID,
R.[Name] As 'Region', 'PURPOSE1' as purpose
From ProjectCompany E Left Join ProjectOffice P On E.ProjectOfficeID = P.ProjectOfficeID
Left Join Company C On E.CompanyID = C.CompanyID
Left Join Region R On P.RegionID = R.RegionID

UNION ALL

Select P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID, R.[Name] As 'Region',
C.CountryID, C.[Name] As 'Country', 'PURPOSE2' as purpose
From ProjectOfficeCountry O Left Join ProjectOffice P On O.ProjectOfficeID = P.ProjectOfficeID
Left Join Country C On O.CountryID = C.CountryID
Left Join Region R On P.RegionID = R.RegionID

Note that you would also need to genericize the other names, like the id, the name, etc. I almost feel wrong in suggesting this, because it seems so much cleaner to make N result sets and get the data one set at a time (much cleaner and certainly eaiser to implement.)

|||

Thanks for the reply Louis.

It seems there is no exact way getting all data needed in just one sql statement. I would stick to using multiple sql statements in getting the results.

Thanks.

I think the issue in this thread is closed.

Connected users

does anybody know how I get to obtain the number or connected users' list in
a base SQL Server for license control?
In Access I get through the function LDBUser_GetUsers of msldbusr.dll.
Thank you.Try sp_who.
All of the SPIDS below 20, I believe, are system and not counted as "users"
"Frank Dulk" <fdulk@.bol.com.br> wrote in message
news:u3n9TfncDHA.3708@.tk2msftngp13.phx.gbl...
>
> does anybody know how I get to obtain the number or connected users' list
in
> a base SQL Server for license control?
> In Access I get through the function LDBUser_GetUsers of msldbusr.dll.
> Thank you.
>|||In SQL2K spids 1-50 are reserved for internal use
--
Ray Higdon MCSE, MCDBA, CCNA
--
"Morgan" <mfears@.spamcop.net> wrote in message
news:OZ0TLzncDHA.2308@.TK2MSFTNGP12.phx.gbl...
> Try sp_who.
> All of the SPIDS below 20, I believe, are system and not counted as
"users"
> "Frank Dulk" <fdulk@.bol.com.br> wrote in message
> news:u3n9TfncDHA.3708@.tk2msftngp13.phx.gbl...
> >
> >
> >
> > does anybody know how I get to obtain the number or connected users'
list
> in
> > a base SQL Server for license control?
> >
> > In Access I get through the function LDBUser_GetUsers of msldbusr.dll.
> >
> > Thank you.
> >
> >
>|||Thanks for the clarification, Ray. Much appreciated.
"Ray Higdon" <rayhigdon@.higdonconsulting.com> wrote in message
news:ukjY87ncDHA.2112@.TK2MSFTNGP10.phx.gbl...
> In SQL2K spids 1-50 are reserved for internal use
> --
> Ray Higdon MCSE, MCDBA, CCNA
> --
> "Morgan" <mfears@.spamcop.net> wrote in message
> news:OZ0TLzncDHA.2308@.TK2MSFTNGP12.phx.gbl...
> > Try sp_who.
> >
> > All of the SPIDS below 20, I believe, are system and not counted as
> "users"
> >
> > "Frank Dulk" <fdulk@.bol.com.br> wrote in message
> > news:u3n9TfncDHA.3708@.tk2msftngp13.phx.gbl...
> > >
> > >
> > >
> > > does anybody know how I get to obtain the number or connected users'
> list
> > in
> > > a base SQL Server for license control?
> > >
> > > In Access I get through the function LDBUser_GetUsers of msldbusr.dll.
> > >
> > > Thank you.
> > >
> > >
> >
> >
>