Saturday, February 25, 2012

Data Access Pages and SQL-Server

Dear All,

I have developed a Data Access Page with Access as a project. It is
connected to a SQL-Server database. I try to edit the data in the table and
am not able to do so. I might be missing some permissions. I have changed
a number. What am I missing?

Thanks in advance.

Jeff MagouirkIf the SQL table does not have a primary index (key), your Access program
can NOT update the table. I am 90% sure this is your problem.

Oscar...

"Jeff Magouirk" <magouirkj@.njc.org> wrote in message
news:10psm909drc4ea6@.corp.supernews.com...
> Dear All,
> I have developed a Data Access Page with Access as a project. It is
> connected to a SQL-Server database. I try to edit the data in the table
and
> am not able to do so. I might be missing some permissions. I have
changed
> a number. What am I missing?
> Thanks in advance.
> Jeff Magouirk

Data access method

I have built a WM5 SQLce2005 application using, primarily, table adapters which sparked a discussion whether it is more effiecent to use table adapters or use SQLce command execution with coding for a device.

Are there any papers / threads or thoughts as to the best access method to use?

The best access method in terms of performance and memory overhead is SQLCeResultset and SQLCEdatareader. There are various performance papers out there, for example: http://msevents.microsoft.com/cui/WebCastEventDetails.aspx?culture=en-US&EventID=1032307726&CountryCode=US

Data Access layer Advice

I've been following Soctt Mitchell's tutorials on Data Access and in Tutorial 1 (Step 5) he suggests using SQL Subqueries in TableAdapters in order to pick up extra information for display using a datasource.

I have two tables for a gallery system I'm building. One called Photographs and one called MS_Photographs which has extra information about certain images. When reading the MS_Photograph data I also want to include a couple of fields from the related Photographs table. Rather than creating a table adapter just to pull this data I wanted to use the existing MS_Photographs adapter with a query such as...

1SELECT CAR_MAKE, CAR_MODEL,2 (SELECT DATE_TAKEN3FROM PHOTOGRAPHS4WHERE (PHOTOGRAPH_ID = MS_PHOTOGRAPHS.PHOTOGRAPH_ID))AS DATE_TAKEN,5 (SELECT FORMAT6FROM PHOTOGRAPHS7WHERE (PHOTOGRAPH_ID = MS_PHOTOGRAPHS.PHOTOGRAPH_ID))AS FORMAT,8 (SELECT REFERENCE9FROM PHOTOGRAPHS10WHERE (PHOTOGRAPH_ID = MS_PHOTOGRAPHS.PHOTOGRAPH_ID))AS REFERENCE,11 DRIVER1, TEAM, GALLERY_ID, PHOTOGRAPH_ID12FROM MS_PHOTOGRAPHS13WHERE (GALLERY_ID = @.GalleryID)
This works but I wanted to know if there's a way to get all of the fields using one subquery instead of three? I did try it but it gave me errors for everything I could think of.
Is using a subquery like above the best way when you want this many fields from a secondary table or should I be using another approach. I'm using classes for the BLL as well and wondered if there's a way to do it at this stage instead?

Can't you simply right a query containing a join like so:

SELECTA.CAR_MAKE,A.CAR_MODEL,B.DATE_TAKEN, B.FORMAT,B.REFERENCE,A.DRIVER1,A.TEAM,A.GALLERY_ID,A.PHOTOGRAPH_IDFROMMS_PHOTOGRAPHSAS AINNERJOIN PHOTOGRAPHSAS BON B.PHOTOGRAPH_ID = A.PHOTOGRAPH_IDWHEREA.GALLERY_ID = @.GalleryID
|||

You can use a join but the tutorial explains that this affects the auto-generated methods for inserting, updating and deleting data using the table adapter.

|||

If I understand your problem correctly it sounds like what you want is a join (perhaps an outer join):

select a.car_make, a.car_model, b.date_taken, b.format, b.reference., etc
from ms_photographs a,
photographs b
where a.photographs_id = b.photographs_id
and a.gallery_id = @.GalleryID

The only issue is that the above query is an "inner" join which means that it will only return data that have matching rows in each table. If you might have data from ms_photographs that is not in photograps, then you need an "outer" join, which just means a change to the where clause as follows:

where a.photographs_id *= b.photographs_id
and a.gallery_id = @.GalleryID

There is an alternate syntax involving the use of the words LEFT OUTER JOIN (which is what the above example is) or RIGHT OUTER JOIN, but I prefer the *= syntax (only because I'm old and that's how I learned itSmile This alternate syntax is the new standard, but the old way is still quite common. Here is the above rewritten to the new standard:

select a.car_make, a.car_model, b.date_taken, b.format, b.reference., etc
from ms_photographs a left outer join photographs b
on a.photographs_id = b.photographs_id
where a.gallery_id = @.GalleryID

BTW, the 2 syntaxes do not actually produce identical output in all cases, but the differences are very subtle and have to do with what happens if you include a where condition on the outer table -- it's not worth going into at this point

|||

Thanks for your suggestion. I can see how that would work but I'm trying to avoid it as the tutorial states that it will affect the other autogenerated statements in the tableadapter if i use a join.

Is there any sensible way to do this without a join or in the BLL?

Cheers

|||

nevets2001uk2:

Is there any sensible way to do this without a join or in the BLL?

I don't see how. Either you use a join or your do all the lookups yourself.

|||

nevets2001uk2:

I've been following Soctt Mitchell's tutorials on Data Access and in Tutorial 1 (Step 5) he suggests using SQL Subqueries in TableAdapters in order to pick up extra information for display using a datasource.

I have two tables for a gallery system I'm building. One called Photographs and one called MS_Photographs which has extra information about certain images. When reading the MS_Photograph data I also want to include a couple of fields from the related Photographs table. Rather than creating a table adapter just to pull this data I wanted to use the existing MS_Photographs adapter with a query such as......

 

You can have multiple select methods - for example, the GetAll and GetByID are common. So if you are not dealing with ginormous volumes and millions of hits, just stick the 3 subqueries in and see how it goes. I dont think SQL Server will physically read the second table three times per row. You can another select method without the subqueries for perfomance if you like. You don'tneed another adapter, though youcould have one if you wanted.

|||

Thanks for the advice. I'll stick with what I have for now and see how I go.

Data Access Laws In the UK

Hi Everyone

This is a data base question so don't switch off thinking it is a Data
Protection Act Question.

I'm Looking for some general information regarding the UK Law on
rights to access data within a database provided by a third party
software provider.

They are preventing me from ODBC Access to their data base and say
that the only way I can access the data held in the data base is
through CSV reports that their custom app can provide.

I am building a datawarehouse and require the data to be DTS'sed to my
OLAP server on a regular basis...but theyt rae denying me access the
database is Oracle so their should really be no problems but they are
hitting me with all the usual invalidate warranty claims.

Does anyone know what UK law has to say in this matter, o0r can you
point me to a good resource.

TIA

Maria"Maria" <nottyshagger69@.yahoo.co.uk> wrote in message
news:e4ba2d0e.0405130142.352a0aee@.posting.google.c om...
> Hi Everyone
> This is a data base question so don't switch off thinking it is a Data
> Protection Act Question.
> I'm Looking for some general information regarding the UK Law on
> rights to access data within a database provided by a third party
> software provider.
> They are preventing me from ODBC Access to their data base and say
> that the only way I can access the data held in the data base is
> through CSV reports that their custom app can provide.
> I am building a datawarehouse and require the data to be DTS'sed to my
> OLAP server on a regular basis...but theyt rae denying me access the
> database is Oracle so their should really be no problems but they are
> hitting me with all the usual invalidate warranty claims.
> Does anyone know what UK law has to say in this matter, o0r can you
> point me to a good resource.
> TIA
> Maria

(from a non-legal background)

It sounds to me as though you've got a efw questions tied into one here.

--

If this is a third-party software provider, then what is your contract with
them ? Are they supplying you with the right to the data (in whatever way
that you wish), or are they supplying software to you that will allow you to
access their data.

The fact that their database server is running Oracle (or MySQL or SQL
Server) shouldn't matter - this would seem to come down to an issue of what
they have committed to providing

There is a difference between "read-only access direct to their database"
(where you can control any filters / queries ) and "access to data from
their database" (where they charge you for providing a report or
data-extract based on your request)

--

I can see nothing here that would have anything to do with a warranty --
maybe they think that by providing you access to their database, they have
lost 100% control of it, so will refuse to support it .

Just a thought

Steven|||I have recently dealt with a similar issue, and there's more than just a legal
question involved. Since the company is selling you a system based on its
external behavior, they are not committing to maintain the same internal
structure each time the product is updated.

In looking at the internal structure of one program I'm trying to get data out
of, I see that the internal structures change with some frequency over time.
Thus, the wise choice for reliably getting data out of this system is to only
use the documented interfaces to the application which the provider has
committed to maintain, and provide documentation on any changes to.

Yes, someone has to manually export the data, and yes, it's silly that I have
to re-normalize data that probably comes out of a normalized structure to
begin with, but that's still the most reliable answer. I would also talk to
your data provider about providing you some sort of ActiveX interface that
could at least be automated, and could provide the data in a more robust
format than csv (e.g. disconnected ADO recordset or XML).

On 13 May 2004 02:42:59 -0700, nottyshagger69@.yahoo.co.uk (Maria) wrote:

>Hi Everyone
>This is a data base question so don't switch off thinking it is a Data
>Protection Act Question.
>I'm Looking for some general information regarding the UK Law on
>rights to access data within a database provided by a third party
>software provider.
>They are preventing me from ODBC Access to their data base and say
>that the only way I can access the data held in the data base is
>through CSV reports that their custom app can provide.
>I am building a datawarehouse and require the data to be DTS'sed to my
>OLAP server on a regular basis...but theyt rae denying me access the
>database is Oracle so their should really be no problems but they are
>hitting me with all the usual invalidate warranty claims.
>Does anyone know what UK law has to say in this matter, o0r can you
>point me to a good resource.
>TIA
>Maria

data access in SqlUserDefinedAggregate

i'm trying to access the DB from the "Accumulate" method in my SqlUserDefinedAggregate. but i get the error:

Data access is not allowed in this context. Either the context is a function or method not marked with DataAccessKind.Read or SystemDataAccessKind.Read, is a callback to obtain data from FillRow method of a Table Valued Function, or is a UDT validation method.

the problem is that DataAccessKind only exists in SqlMethodAttribute and SqlFunctionAttribute. and they are not good for aggregate functions.

i've tried to call another class (class file that is not defined as aggregate or sql function) in the same project to do this but i still get this message if its calles from my "Accumulate" method .

Did you read the following from:

Using CLR Integration in SQL Server 2005

"Also, a UDA can perform no data access, nor have side-effects; if either of these are necessary then a stored procedure should be used.Also, a UDA can perform no data access, nor have side-effects; if either of these are necessary then a stored procedure should be used."

Jens K. Suessmeyer.

http://www.sqlserver2005.de

Data access in a variable

Hello Friends

i have one problem, i have to need fatch the data from database .

in the web form i take three grid view and i put the query "Select Top 1 coloum1 from tanlename order by newid()" .

when the data came from database there is no sequence series . so i want to take fatch the data from database in variable like int a , b , c and call the data in those variable

and put up in the feild

example :- welcome to Mr "Data call from data base (1) " how are you "Data call from data base (2)" bbye and "Data call from data base (3)"

Answer "- welcome to Mr "ASHWANI" how are you FINE OR NOT" bbye and "TAKE CARE"

there is all capslock on value came from databse and these value in the web page store in a variable

like int a ;

int b;

int c;

please help me please i have a huge problem

Ashwnai

Hi ashwani2kumar,

Not 100% sure what you mean. How do you fetch those data from your database? what does you select query look like?

welcome to Mr "Data call from data base (1) " how are you "Data call from data base (2)" bbye and "Data call from data base (3)"

Answer "- welcome to Mr "ASHWANI" how are you FINE OR NOT" bbye and "TAKE CARE"

If your string is fixed, i mean, those "welcoem to, how are you ..etc" stuff are fixed, i think you can assemble that string within a stored procedure, like this:

create procedure sp_string par1_defination,par2_defination,// i don't know how do you fetch those data, so, fill in those query parameters by yourself@.ret_str varchar(200) outputasdeclare @.str1 varchar(20),@.str2 varchar(20),@.str3 varchar(30)select @.str1=Namefrom table1 where// your query 1select @.str2=colnamefrom table2 where// your query 2select @.str3=colnamefrom table3 where// your query 3set @.ret_str='welcome to Mr'+@.str1+'how are you'+@.str2+'bbye and'+@.str3return
Hope my suggestion helps

Data access From sqlserver 2000

Hello

i have one prob . i m using sql server 2000 . and i have write a store procedure to fetch data from multiple table using cursor . this query exculate in sql server . but i can't fetch this data from in our page . how to fetch data from using multiple table .plz help

thnx

Hi shruram.gore,

You don't need to use cursor for this unless you need to do some operations (processess) before displaying the data.
Cursor will not help you in displying the data, to display the data use SELECT and if you need to fetch the data from more than one table, use JOIN.

Example:

SELECT a.col1, a.col2, b.col2FROM table1 aINNERJOIN table2 bon (a.id = b.id)

Good luck.

|||

thnx , for suggestion

But dont have fix table name . in my prob my table name is variable plz check the query . this query we will use to bind treeView to show parent child releation . i have execute data from this query but we cant fetch data in dataset

thanx in advance

CREATE PROCEDURE [dbo].GetRootChild
AS

SET TRANSACTION ISOLATION LEVEL READ COMMITTED
declare @.parentId int
declare @.TableName varchar (50)
declare @.RelIDName char(10),@.s int,@.sql varchar(4000)

declare comments_list CURSOR FOR
select distinct [PcRelation].[ChID],[ObjectType].[ObjName],[ObjectType].[RelIdName] from PcRelation,ObjectType where [PcRelation].[ChObjectID]=[ObjectType].[ID] and [PcRelation].[PID]='0' and [PcRelation].[PObjectID]='0'
OPEN comments_list
FETCH NEXT FROM comments_list INTO @.parentId,@.TableName,@.RelIDName
WHILE @.@.FETCH_STATUS = 0
BEGIN
DECLARE product_cursor CURSOR FOR
select @.TableName as TableName
--select * from Company
select @.sql ='select * from [dbo].['+ @.TableName +'] where ['+ @.TableName +'].['+@.RelIDName+']= '+convert(char(10),@.parentId)+''
OPEN product_cursor
FETCH NEXT FROM product_cursor
WHILE @.@.FETCH_STATUS = 0
BEGIN
--select @.TableName as TableName
exec(@.sql)
FETCH NEXT FROM product_cursor
END
CLOSE product_cursor
DEALLOCATE product_cursor
FETCH NEXT FROM comments_list INTO @.parentId,@.TableName,@.RelIDName
END
CLOSE comments_list
DEALLOCATE comments_list
GO

and fetch data from sql

if cant image refer this url

http://shriramgore.ifastnet.com/?q=node/41

thnx

|||

Hi,

Based on my understing, since you didn't do any row-based operations on the table(after you have fetched each row, seems you didn't perform any operations), there is no need for you to use cursors. If what you want is just to fetch data from multi tables, a simpleJoin will work in your case. Use dynamic query if you cannot determine your table name until run-time. Like:

declare @.str nvarchar(100) ,@.str1 varchar(100)set @.str='table_1'set @.str1='table_2'exec ('select * from '+@.str+' as a inner join '+ @.str1+' as b on a.id=b.id')
Hope my suggestion helps|||

thnx for replyBo Chen

but i have following like ......... please check example ...

I have data from multiple table, those table's Names are store as Variable in a table . in this Case i have written 1 store procedure using Cursor . this query Execute in server like (Please check this Url -http://shriramgore.ifastnet.com/?q=node/41&size=_original ) . after executing storeprocedure i get data in different tabels this data i can't fetch in single dataset .if i will fetch all tables(results of storeprocedure) then it eaiser to me for next part .

e.g
DataSet ds = new DataSet();
ds = proc.GetDataSet();


for (int i= 0; i< ds.Tables.Count; i++)
{
for (int y= 0; y< ds.Tables [i].Rows.Count; y++)
{
String str=ds.tabels[i].rows[y]["ColumnName"].toString();
}
}

in this example i enable to get other tabels (dsParent1.Tables[int] ).

please help

thnx in advance

|||

Hi shriram.gore,

I can see your problem. In my opinion, i think you can try to revise your stored procedure, like this: pass three or four parameters(as you need) into your stored procedure and make them as output paramters. In your stored procedure, you can assign them the table-name values during sql clause execution. For example:

create procedure sp_get_tbl_name (@.str1 varchar(100) output,
@.str2 varchar(100) output, @.str3 varchar(100) output...)
as
select @.str1=tablename
from yourtablename
where .....
go
select @.str2=tablename
from yoursecondtablename
where...
go
..

Hope my suggestion helps

|||

Hello ,

thnx for Reply

Yes uropinion is correct . That query iwould like to use in for loop to fetch data from multiple table . m i rt . in my case i can't use for loop in my page bcoz we have 200 record's from 5 table (Varible table - those declare in other table).if i had use for loop then those query fire 200 time . m i rt .

excuse i m not using sqlserver 2005

thnx

shriram

|||

Yes uropinion is correct . That query iwould like to use in for loop to fetch data from multiple table . m i rt . in my case i can't use for loop in my page bcoz we have 200 record's from 5 table (Varible table - those declare in other table).if i had use for loop then those query fire 200 time . m i rt .

If i understand you correct, that's not a problem.

Since now you have got those table names, you can user your sldataadpater to perform a sql data retrieval against each data table name--after that you will get server datasets, say, ds1, ds2,ds3,ds4..etc. Generally speaking each dataset you get contains only one table(it depends on your select command)

Then you can create a new dataset named ds, run : ds.tables.add(ds1.table[0]); ds.tables.add(ds2.table[0]),ds.tables.add(ds3.table[0])...etc..

Now your dataset ds contains all the tables you need. You can perform your loop on it.

BTW, what does "m i rt. " stand for??

thanks

|||

HelloBo Chen ,

thank u very much . my prob is solved .

thnx

shriram