Showing posts with label complex. Show all posts
Showing posts with label complex. Show all posts

Sunday, March 25, 2012

Datasets, searching, complex queries.

Alright just starting out in ASP.NET and it's making my head spin, but I think I'm getting it.

My schema in brief : Images, Categories, and a table in the middle so we can have a many-to-many relationship between images and categories. My issue is searching. I can search by keyword, and limit it to categories. So, in pseudo sql..


SELECT ... WHERE keyword LIKE '%test%' and category_id in (1,5,20,66);


I made a variable for the keyword no problem. But how can I get this dynamic list? Or, is there another way about going this problem?

Where will you put your query in? StoredProcedure or Web? I think my two posts help you:

http://forums.asp.net/t/1162993.aspx

http://forums.asp.net/t/1158548.aspx

|||

I've been informed by the big shark guy that I recommend D-SQL a lot, but you are asking for it so here goes:

First off... beware SQL injection. Strip out ' and - from your search text. Do without.

CREATE PROCEDURE sp_search @.keyword varchar(50),
@.categorylist varchar(150) as

declare @.sql varchar(max)

set @.sql = 'SELECT ... WHERE keyword LIKE ''%' + @.keyword + '%'' and category_id in (' + @.categorylist + ')' -- BTW those are double single quotes, not double quotes

EXEC sp_executesql @.sql, N'@.keyword varchar(50), @.categorylist varchar(150)'

then call sp_search in your code, adding the keyword and category list strings as parameters. Does that help?

|||

che : i'll read those links now

Charles : Interesting. Will I be able to accomplish something like this with Oracle? That looks like SQL Server to me?

|||

Oh. Most folks here are SQL Server. I'm sure you can do dynamic SQL in oracle though - my boss who taught me D-SQL co-authored the Oracle Designer/2000 Handbook. The sp_executesql is a SQL serber built-in sp, and I don't know what the equivalent is in oracle:

http://lbdwww.epfl.ch/f/teaching/courses/oracle8i/server.815/a68022/dynsql.htm

|||

This is a little disappointing. Dynamic SQL seems really overkill for such a trivial problem.

Perhaps I should look at not using strongly typed Datasets? Build one on the fly? Would that be different/better?

|||

Many of the problems were have these days tend to be ones caused by the complexity of the frameworks we are working in. For example, to write a web page, I have to know C# (or VB), ASP, HTML, SQL, and .Net, and how they all interrelate. For one page. It used to be that all you needed was a front end and a database. Oh well, we get a lot in terms of scalability and functionality out of this stuff too - the complexity is market driven.

All philosophy aside, it seems to me that most searches are done with D-Sql. If you really want to make a mountain out of a molehill, you could create a search object that safely builds your query in C# and then access it from your search front end. The advantage of that would be that you could get a lot of re-use in the future. Searching is a non-trivial issue. The volume of work that has gone into searching makes it difficult to mine for simple one-off solutions.

sql

DataSet works... DataTable doesnt... (ODBC)

I have a longstanding problem where Stored Procedures or complex T-SQL called from VB.NET will not populate a DataTable object, but will work fine with a DataSet. For example:

'oConn is defined elsewhere...
Dim sErr as String = ""
Dim dt As New DataTable
If Not oConn Is Nothing Then
Try
Dim sSQL as String = "select 1"
Dim oCommand As New OdbcDataAdapter(sSQL, oConn)
oCommand.Fill(dt)
Catch ex As Exception
sErr = "Database Error: " & ex.Message
Finally
sqlCloseConnection(oConn)
End Try
End If

this works fine and my dt DataTable object gets one row. However using this as the SQL:

Dim sSQL as String = "declare @.foo table(mycol integer);insert @.foo select 1;select mycol from @.foo;"

does not work. It executes with no errors, but the DataTable has no rows. Finally, if I replace the DataTable with:

Dim ds as DataSet

I can then get the data in ds.Tables(0) no problem.

So, if the results of the sql are a single result table being put at index 0 of a DataSet, why are they not being put in a single DataTable?

When a sql is a simple select statement it always works directly to a DataTable. Only when it's a SP or sql with some logic does it require the DataSet approach. This is a reporting utility so I need to standardize the code though the sql will be dynamic.


Any ideas?


Hello my friend,

I tried your code in my application and it worked for me, but I am using the SqlDataAdapter. Why are you using Odbc? Try using the Connection, Command, DataAdapter, etc classes from the System.Data.SqlClient namespace and I think it will work.

Kind regards

Scotty

Thursday, March 22, 2012

Dataset problems with Stored Procedures.

I've noticed that SP:s that are more complex than just a simple
SELECT-statement don't work correctly when creating new datasets. The dataset
can't seem to populate the Fields when the SP does some additional work
before the SELECT. I know it's possible to create all the Fields manually,
but that isn't an option for us since we have a ton of reports with lots and
lots of fields. Is there another workaround for this? Maybe in SQL Server
2005?No answers? Is there really no way to solve this? This problem could be a
real show stopper for our current project...
"Patrik Ylén" wrote:
> I've noticed that SP:s that are more complex than just a simple
> SELECT-statement don't work correctly when creating new datasets. The dataset
> can't seem to populate the Fields when the SP does some additional work
> before the SELECT. I know it's possible to create all the Fields manually,
> but that isn't an option for us since we have a ton of reports with lots and
> lots of fields. Is there another workaround for this? Maybe in SQL Server
> 2005?|||Have you tried the refresh fields button (to the right of the ...)?
I have SP that do a lot (put data into multiple temp tables etc). The very
last statement is the select. So having stuff above the select matters not
at all. Sometimes I have to click on the refresh fields.
How are you calling the SP (i.e. are you doing an exec or have you set the
command type to stored procedure).
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Patrik Ylén" <PatrikYln@.discussions.microsoft.com> wrote in message
news:FB603E2E-CBD1-4773-BF3C-7B4EC6B328A6@.microsoft.com...
> No answers? Is there really no way to solve this? This problem could be a
> real show stopper for our current project...
> "Patrik Ylén" wrote:
>> I've noticed that SP:s that are more complex than just a simple
>> SELECT-statement don't work correctly when creating new datasets. The
>> dataset
>> can't seem to populate the Fields when the SP does some additional work
>> before the SELECT. I know it's possible to create all the Fields
>> manually,
>> but that isn't an option for us since we have a ton of reports with lots
>> and
>> lots of fields. Is there another workaround for this? Maybe in SQL Server
>> 2005?|||Hmm, it works now. I don't know what I did when I tried it the last time, but
it must've been wrong! :-)
Thanks,
Patrik
"Bruce L-C [MVP]" wrote:
> Have you tried the refresh fields button (to the right of the ...)?
> I have SP that do a lot (put data into multiple temp tables etc). The very
> last statement is the select. So having stuff above the select matters not
> at all. Sometimes I have to click on the refresh fields.
> How are you calling the SP (i.e. are you doing an exec or have you set the
> command type to stored procedure).
>
> --
> Bruce Loehle-Conger
> MVP SQL Server Reporting Services
> "Patrik Ylén" <PatrikYln@.discussions.microsoft.com> wrote in message
> news:FB603E2E-CBD1-4773-BF3C-7B4EC6B328A6@.microsoft.com...
> > No answers? Is there really no way to solve this? This problem could be a
> > real show stopper for our current project...
> >
> > "Patrik Ylén" wrote:
> >
> >> I've noticed that SP:s that are more complex than just a simple
> >> SELECT-statement don't work correctly when creating new datasets. The
> >> dataset
> >> can't seem to populate the Fields when the SP does some additional work
> >> before the SELECT. I know it's possible to create all the Fields
> >> manually,
> >> but that isn't an option for us since we have a ton of reports with lots
> >> and
> >> lots of fields. Is there another workaround for this? Maybe in SQL Server
> >> 2005?
>
>|||"Bruce L-C [MVP]" wrote:
> Have you tried the refresh fields button (to the right of the ...)?
> I have SP that do a lot (put data into multiple temp tables etc). The very
> last statement is the select. So having stuff above the select matters not
> at all. Sometimes I have to click on the refresh fields.
> How are you calling the SP (i.e. are you doing an exec or have you set the
> command type to stored procedure).
>
> --
> Bruce Loehle-Conger
> MVP SQL Server Reporting Services
> "Patrik Ylén" <PatrikYln@.discussions.microsoft.com> wrote in message
> news:FB603E2E-CBD1-4773-BF3C-7B4EC6B328A6@.microsoft.com...
> > No answers? Is there really no way to solve this? This problem could be a
> > real show stopper for our current project...
> >
> > "Patrik Ylén" wrote:
> >
> >> I've noticed that SP:s that are more complex than just a simple
> >> SELECT-statement don't work correctly when creating new datasets. The
> >> dataset
> >> can't seem to populate the Fields when the SP does some additional work
> >> before the SELECT. I know it's possible to create all the Fields
> >> manually,
> >> but that isn't an option for us since we have a ton of reports with lots
> >> and
> >> lots of fields. Is there another workaround for this? Maybe in SQL Server
> >> 2005?
> HI!
>I have a related problem. My stored procedure returns a different dataset based on an entered parameter - it returns a particular set of data for display in the report detail (@.showdetail) and another set for display in the report footer (@.showfooter)
When I call the stored procedure from within reporting services (either by
exec spname @.parameter as a text entry, or by referencing it's name) I can
retrieve the 2 separate datasets fine (ie the results sets show up in the
grid). HOWEVER, changing the parameter to 'showfooter' instead of
'showdetail' does not update the associated field list. Which means I can't
drag the second dataset's fields onto my layout.
Any ideas?|||RS only supports one dataset being returned from the SP. If you have a
single stored procedure that returns multiple datasets then you either need
to modify the stored procedure to return the appropriate dataset based on a
parameter or you need to split it into two stored procedure.
Note that you can have many many datasets in your report. You just cannot
have a stored procedure return more than one dataset. And, no, this has not
changed with 2005.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"GavinMc" <GavinMc@.discussions.microsoft.com> wrote in message
news:28DDEFA3-2903-4E8B-B56E-15757E303832@.microsoft.com...
>
> "Bruce L-C [MVP]" wrote:
>> Have you tried the refresh fields button (to the right of the ...)?
>> I have SP that do a lot (put data into multiple temp tables etc). The
>> very
>> last statement is the select. So having stuff above the select matters
>> not
>> at all. Sometimes I have to click on the refresh fields.
>> How are you calling the SP (i.e. are you doing an exec or have you set
>> the
>> command type to stored procedure).
>>
>> --
>> Bruce Loehle-Conger
>> MVP SQL Server Reporting Services
>> "Patrik Ylén" <PatrikYln@.discussions.microsoft.com> wrote in message
>> news:FB603E2E-CBD1-4773-BF3C-7B4EC6B328A6@.microsoft.com...
>> > No answers? Is there really no way to solve this? This problem could be
>> > a
>> > real show stopper for our current project...
>> >
>> > "Patrik Ylén" wrote:
>> >
>> >> I've noticed that SP:s that are more complex than just a simple
>> >> SELECT-statement don't work correctly when creating new datasets. The
>> >> dataset
>> >> can't seem to populate the Fields when the SP does some additional
>> >> work
>> >> before the SELECT. I know it's possible to create all the Fields
>> >> manually,
>> >> but that isn't an option for us since we have a ton of reports with
>> >> lots
>> >> and
>> >> lots of fields. Is there another workaround for this? Maybe in SQL
>> >> Server
>> >> 2005?
>> HI!
>>I have a related problem. My stored procedure returns a different dataset
>>based on an entered parameter - it returns a particular set of data for
>>display in the report detail (@.showdetail) and another set for display in
>>the report footer (@.showfooter)
> When I call the stored procedure from within reporting services (either by
> exec spname @.parameter as a text entry, or by referencing it's name) I can
> retrieve the 2 separate datasets fine (ie the results sets show up in the
> grid). HOWEVER, changing the parameter to 'showfooter' instead of
> 'showdetail' does not update the associated field list. Which means I
> can't
> drag the second dataset's fields onto my layout.
> Any ideas?|||Thanks Bruce
My stored procedure is actually coded to return an appropriate dataset based
on a parameter which is supplied when calling the sp in RS. It returns the
appropriate dataset to the results grid fine in RS using the supplier
parameters. The fields returned in both datasets are completely different.
The problem is that the field list is not updated when I change the
parameter, it remains the list associated with the first parameter supplied
even if click 'refresh fields' after changing the parameter
I need my report to use the two separate datasets without having to re-write
the sp which is pages long.
Is this related to the fact that you can't have a sp return more than one
dataset in rs'|||Logically, you are returning two datasets. Depending on the parameter you
get a different field list. What you need to do is call the SP two times in
design mode with different parameters to get the different field list. Then
design your form with these and hide the one you don't want based on the
parameter.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"GavinMc" <GavinMc@.discussions.microsoft.com> wrote in message
news:F34F84BB-226F-4A34-A0ED-551137DCA065@.microsoft.com...
> Thanks Bruce
> My stored procedure is actually coded to return an appropriate dataset
> based
> on a parameter which is supplied when calling the sp in RS. It returns
> the
> appropriate dataset to the results grid fine in RS using the supplier
> parameters. The fields returned in both datasets are completely different.
> The problem is that the field list is not updated when I change the
> parameter, it remains the list associated with the first parameter
> supplied
> even if click 'refresh fields' after changing the parameter
> I need my report to use the two separate datasets without having to
> re-write
> the sp which is pages long.
> Is this related to the fact that you can't have a sp return more than one
> dataset in rs'sql

Monday, March 19, 2012

Datareader Destination as source for other datareader source ?

HI!

as far as I know from docs and forum datareader is for .NET data in memory. So if a use a complex dataflow to build up some data and want to use this in other dataflow componens - could i use data datareader source in the fist dataflow and then use a datareader souce in the second dataflow do read the inmemoty data from fist transform to do fursther cals ?

how to pass in memory data from one dataflow to the next one (i do not want to rebuild the logic in each dataflow to build up data data ?

Is there a way to do this ? and is the datareader the proper component ? (because its the one and only inmemory i guess, utherwise i need to write to temp table and read from temp table in next step) (I have only found examples fro .NET VB or C# programms to read a datareader, but how to do this in SSIS directly in the next dataflow?

THANKS, HANNES

Hannes,

You would need to build an ADO.Net provider for SSIS packages in order to do this. We have built one at Conchango but I think my boss is reluctant for us to just give it away.

-Jamie

|||

Hi Jamie!

I could understand your boss..

I would expect there is some integrated way because it is essential to get data from one dataflow to an other dataflow.

Do you know any othere method (without temp tables) to move data from one dataflow to to next?

I do not understand the difference between datareader and oledb source/dest? is there reader only for .NET Programming, oder is there a special purpose for this objects i do not realize (it seems to be the same escape for integration with other .NET data consumer which could read the Datareader...)

THANKS, HANNES

|||

hannes,

I have just realised that I completely misunderstood your first post. I apologise for that.

The answer I gave previously applies if you want to pass data from one PACKAGE to another. I realise now that what you want to do is pass data from DATA-FLOW to another. You have 2 options for doing that. Raw files or ADO recordsets.

I compare the two here: http://blogs.conchango.com/jamiethomson/archive/2006/06/28/4159.aspx and its pretty conclusive about which you should use.

Again, my apologies for misreading your initial post!

-Jamie

P.S. Hannes, are you still at MISAG?

|||

That is it, but what I cannot understand why there is no in memory way.

THANKS

PS: No! - AVENESS - see signature for further details (for the moment only in german)

|||

There is - the ADO recordset destination provides this functionality. Admittedly you have to write code to access it again in a script source component but this is because the metadata of the recordset is not (and cannot be) persisted in the Object variable at design-time.

-Jamie

Friday, February 17, 2012

Database views hierarchy

Hello:
In my SQL Server databases I have complex related tables and views.
There is any tool which allow you to see (print) this complex hierarchy of
views and tables as hierarchical tree?

Thanks,
GBHave you tried the SQL Server Diagraming tools ? This will at least be
able to give you data model to work with. I recall somewhere that
coding some nifty SQL SMO may help.

MJKulangara
http://sqladventures.blogspot.com|||I tried to create database diagrams but it shows table relations only.

GB

"MJKulangara" <RutgersDBA@.gmail.com> wrote in message
news:1138914523.816837.42350@.o13g2000cwo.googlegro ups.com...
> Have you tried the SQL Server Diagraming tools ? This will at least be
> able to give you data model to work with. I recall somewhere that
> coding some nifty SQL SMO may help.
> MJKulangara
> http://sqladventures.blogspot.com|||GB (v7v1k3@.hotmail.com) writes:
> In my SQL Server databases I have complex related tables and views.
> There is any tool which allow you to see (print) this complex hierarchy of
> views and tables as hierarchical tree?

There are several data-modelling tools on the market, that are quite
more eloquent and powerful than the built-in diagamming in SQL Server.
They are also more expensive...

Anyway, the leaders in this field are PowerDesigner (from Sybase), ErWin
(now from Computer Associates) and Embrocadero's tool. I use PowerDesigner
myself, but I don't think it has that much support for showing relation
for views, actually. Then again, I use views very little, so I may have
missed how it works.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx