Tuesday, March 27, 2012
Advice on calculating coupon dates?
advice more than code, but either would be appreciated.
Bonds periodically pay you a "coupon". Typically they do so on anniverseries
of their first coupon date (which we store) or last coupon date (maturity),
some number of times a year (typically 2, 4 or 6 times). I would like to run
a query that shows every bond that is going to pay a coupon within a certain
time, say one week on either side of today, or even just "today" would be
useful.
It would seem that I could potentially calculate this with some clever
"slicing" of the dates. For instance, if the coupon pays every month I could
substitute the month of the test date (July for instance) into the first/last
coupon date and get something reasonable. However this would only work if the
coupon is _this_ month - perhaps the closest one is at the end of last month?
Nor do I see an easy way to handle the non-monthly (or yearly) cases.
Any advice?
Maury
"Maury Markowitz" <MauryMarkowitz@.discussions.microsoft.com> wrote in
message news:C585A270-C0A5-452B-85AC-56A8EFB4A2DA@.microsoft.com...
>I am wondering if anyone has approached this problem before. I'm looking
>for
> advice more than code, but either would be appreciated.
> Bonds periodically pay you a "coupon". Typically they do so on
> anniverseries
> of their first coupon date (which we store) or last coupon date
> (maturity),
> some number of times a year (typically 2, 4 or 6 times). I would like to
> run
> a query that shows every bond that is going to pay a coupon within a
> certain
> time, say one week on either side of today, or even just "today" would be
> useful.
> It would seem that I could potentially calculate this with some clever
> "slicing" of the dates. For instance, if the coupon pays every month I
> could
> substitute the month of the test date (July for instance) into the
> first/last
> coupon date and get something reasonable. However this would only work if
> the
> coupon is _this_ month - perhaps the closest one is at the end of last
> month?
> Nor do I see an easy way to handle the non-monthly (or yearly) cases.
> Any advice?
Break the problem into two problems. For every bond, calculate and store
ahead of time its cupon payment schedule.
create table BondCuponPayment
(
BondID int not null,
CuponDate DateTime not null,
constraint pk_BondPayment primary key (BondID, CuponDate),
Amount decimal(13,2)
)
Then you can run simple queries to retrieve upcoming cupon payments.
David
|||"David Browne" wrote:
> Break the problem into two problems. For every bond, calculate and store
> ahead of time its cupon payment schedule.
I didn't want to do this because it could potentially be an unlimited number
of bonds. So then I "got smart" and did another query on all the things that
we recently had a trade in. That was only 35, which seemed to be OK, it took
aboput 4 seconds.
But then on a lark I just did it for everything in the database. It took 0
seconds.
Sigh. Outsmarted myself again...
Maury
Advice on calculating coupon dates?
advice more than code, but either would be appreciated.
Bonds periodically pay you a "coupon". Typically they do so on anniverseries
of their first coupon date (which we store) or last coupon date (maturity),
some number of times a year (typically 2, 4 or 6 times). I would like to run
a query that shows every bond that is going to pay a coupon within a certain
time, say one week on either side of today, or even just "today" would be
useful.
It would seem that I could potentially calculate this with some clever
"slicing" of the dates. For instance, if the coupon pays every month I could
substitute the month of the test date (July for instance) into the first/last
coupon date and get something reasonable. However this would only work if the
coupon is _this_ month - perhaps the closest one is at the end of last month?
Nor do I see an easy way to handle the non-monthly (or yearly) cases.
Any advice?
Maury"Maury Markowitz" <MauryMarkowitz@.discussions.microsoft.com> wrote in
message news:C585A270-C0A5-452B-85AC-56A8EFB4A2DA@.microsoft.com...
>I am wondering if anyone has approached this problem before. I'm looking
>for
> advice more than code, but either would be appreciated.
> Bonds periodically pay you a "coupon". Typically they do so on
> anniverseries
> of their first coupon date (which we store) or last coupon date
> (maturity),
> some number of times a year (typically 2, 4 or 6 times). I would like to
> run
> a query that shows every bond that is going to pay a coupon within a
> certain
> time, say one week on either side of today, or even just "today" would be
> useful.
> It would seem that I could potentially calculate this with some clever
> "slicing" of the dates. For instance, if the coupon pays every month I
> could
> substitute the month of the test date (July for instance) into the
> first/last
> coupon date and get something reasonable. However this would only work if
> the
> coupon is _this_ month - perhaps the closest one is at the end of last
> month?
> Nor do I see an easy way to handle the non-monthly (or yearly) cases.
> Any advice?
Break the problem into two problems. For every bond, calculate and store
ahead of time its cupon payment schedule.
create table BondCuponPayment
(
BondID int not null,
CuponDate DateTime not null,
constraint pk_BondPayment primary key (BondID, CuponDate),
Amount decimal(13,2)
)
Then you can run simple queries to retrieve upcoming cupon payments.
David|||"David Browne" wrote:
> Break the problem into two problems. For every bond, calculate and store
> ahead of time its cupon payment schedule.
I didn't want to do this because it could potentially be an unlimited number
of bonds. So then I "got smart" and did another query on all the things that
we recently had a trade in. That was only 35, which seemed to be OK, it took
aboput 4 seconds.
But then on a lark I just did it for everything in the database. It took 0
seconds.
Sigh. Outsmarted myself again...
Maury
Advice on calculating coupon dates?
advice more than code, but either would be appreciated.
Bonds periodically pay you a "coupon". Typically they do so on anniverseries
of their first coupon date (which we store) or last coupon date (maturity),
some number of times a year (typically 2, 4 or 6 times). I would like to run
a query that shows every bond that is going to pay a coupon within a certain
time, say one week on either side of today, or even just "today" would be
useful.
It would seem that I could potentially calculate this with some clever
"slicing" of the dates. For instance, if the coupon pays every month I could
substitute the month of the test date (July for instance) into the first/las
t
coupon date and get something reasonable. However this would only work if th
e
coupon is _this_ month - perhaps the closest one is at the end of last month
?
Nor do I see an easy way to handle the non-monthly (or yearly) cases.
Any advice?
Maury"Maury Markowitz" <MauryMarkowitz@.discussions.microsoft.com> wrote in
message news:C585A270-C0A5-452B-85AC-56A8EFB4A2DA@.microsoft.com...
>I am wondering if anyone has approached this problem before. I'm looking
>for
> advice more than code, but either would be appreciated.
> Bonds periodically pay you a "coupon". Typically they do so on
> anniverseries
> of their first coupon date (which we store) or last coupon date
> (maturity),
> some number of times a year (typically 2, 4 or 6 times). I would like to
> run
> a query that shows every bond that is going to pay a coupon within a
> certain
> time, say one week on either side of today, or even just "today" would be
> useful.
> It would seem that I could potentially calculate this with some clever
> "slicing" of the dates. For instance, if the coupon pays every month I
> could
> substitute the month of the test date (July for instance) into the
> first/last
> coupon date and get something reasonable. However this would only work if
> the
> coupon is _this_ month - perhaps the closest one is at the end of last
> month?
> Nor do I see an easy way to handle the non-monthly (or yearly) cases.
> Any advice?
Break the problem into two problems. For every bond, calculate and store
ahead of time its cupon payment schedule.
create table BondCuponPayment
(
BondID int not null,
CuponDate DateTime not null,
constraint pk_BondPayment primary key (BondID, CuponDate),
Amount decimal(13,2)
)
Then you can run simple queries to retrieve upcoming cupon payments.
David|||"David Browne" wrote:
> Break the problem into two problems. For every bond, calculate and store
> ahead of time its cupon payment schedule.
I didn't want to do this because it could potentially be an unlimited number
of bonds. So then I "got smart" and did another query on all the things that
we recently had a trade in. That was only 35, which seemed to be OK, it took
aboput 4 seconds.
But then on a lark I just did it for everything in the database. It took 0
seconds.
Sigh. Outsmarted myself again...
Maurysql
Advice Needed: Where to put ADO Code
I need some advice on a project that I am working on...
First, here is what I am trying to achieve: A Web Form with two controls: A DropDownList with two items added at design time (Fruits and Vegetables) and an empty ListBox. When the user chooses a "category" from the DropDownList, the ListBox will be populated with a list of either "Fruits" or "Vegetables" retrieved from a SQL database. (Note: Since the data in the SQL database must be converted and formatted programatically, simply databinding the ListBox will not work here.)
I believe that I can do this with the following code (stolen from an MSDN article):
'Create ADO.NET objects.Private myConnAs SqlConnectionPrivate myCmdAs SqlCommandPrivate myReaderAs SqlDataReaderPrivate resultsAs String'Create a Connection object. myConn =New SqlConnection("Initial Catalog=Northwind;" & _"Data Source=localhost;Integrated Security=SSPI;")'Create a Command object. myCmd = myConn.CreateCommand myCmd.CommandText ="SELECT FirstName, LastName FROM Employees"'Open the connection. myConn.Open() myReader = myCmd.ExecuteReader()'Concatenate the query result into a string.Do While myReader.Read() results = results & myReader.GetString(0) & vbTab & _ myReader.GetString(1) & vbLfLoop'Display results. MsgBox(results)'Close the reader and the database connection. myReader.Close() myConn.Close()Now here is the part that I am not sure about: Is the FormLoad event the best place to put this code? If I do, is this not a lot of overhead (creating, opening and closing a connection) everytime there is a page refresh/PostBack? Would I be better off putting this code in the DropDownList SelectedIndexChanged event? Although that seems like it could make the process of selecting a category take a fairly long time.
Finally, if the is a better way of doing this, I am certainly open to suggestions.
All advice is greatly appreciated.
hello,
you may like to read "ASP.Net Tutorial - If Not Page.IsPostBack" article at,
http://aspnet101.com/aspnet101/tutorials.aspx?id=3
ALSO,
i'd like to suggest you to read this too,
1) "Examining the Data Access Application Block" at,
http://aspnet.4guysfromrolla.com/articles/070203-1.aspx
2) "Working with the Enterprise Library's Data Access Application Block" at ,
http://aspnet.4guysfromrolla.com/articles/030905-1.aspx
regards,
Niraj sikotara.
Thursday, March 22, 2012
AdventureWorks inserting records to JobCandidates example
re: AdventureWorks example
Are there source code to how the
HumanResources.JobCandidate
table was created?
(I would like to look at the sample code for INSERTing)
thanks
joyceWhat exactly do you want to know about?
Thanks
Michael
PS: I don't think we have sample code for specifically this table...
"joyce chan" <joyceschan@.fastmail.fm> wrote in message
news:1169588888.525240.259000@.j27g2000cwj.googlegroups.com...
> Hi
> re: AdventureWorks example
> Are there source code to how the
> HumanResources.JobCandidate
> table was created?
> (I would like to look at the sample code for INSERTing)
> thanks
> joyce
>|||Actually, what I am really
about is namespace...So I thought I should take a look at how the JobCandidates table was
created in AdventureWorks.
I understand targetnamespace, and
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
I don't really understand default namespace such as
xmlns="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume
"
What is the purpose of the def ns?
And also, what is the purpose of the schema collection? And how come a
schema collection can contain multiple schema.
And what is the advantage of typed vs untyped xml in sql server. Also,
does Sql server support any other types of schemas?
I'm still slowly going through the books online material, but it'd be
nice if all these questions are all answered at once.
Thank you, this is a great usenet group,
Joyce
On Jan 24, 8:05 pm, "Michael Rys [MSFT]" <m...@.online.microsoft.com>
wrote:
> What exactly do you want to know about?
> Thanks
> Michael
> PS: I don't think we have sample code for specifically this table...
> "joyce chan" <joycesc...@.fastmail.fm> wrote in messagenews:1169588888.5252
40.259000@.j27g2000cwj.googlegroups.com...
>
>
>
>
>|||See inline below.
Best regards
Michael
"joyce chan" <joyceschan@.fastmail.fm> wrote in message
news:1169736748.697916.238950@.s48g2000cws.googlegroups.com...
> Actually, what I am really
about is namespace...> So I thought I should take a look at how the JobCandidates table was
> created in AdventureWorks.
> I understand targetnamespace, and
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> I don't really understand default namespace such as
> xmlns="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resu
me"
> What is the purpose of the def ns?
Default namespaces are just a syntactic convenience in that you do not have
to write a prefix (this is true for XML documents and XQuery, but not XPath
1.0 where no support for default namespace exists, you have to define a
prefix for the query).
Namespaces per se are just scoping mechanisms to scope a name to a space
that can have different semantics associated than the same name in a
different namespace... e.g., river:bank vs finance:bank.
> And also, what is the purpose of the schema collection? And how come a
> schema collection can contain multiple schema.
A schema collection is a meta data object in SQL Server that allows you to
combine multiple schemas in a logical unit to constrain and type an XML data
type instance with. It also introduces a way that allows you to have more
than one version of the same schema within your database. Note that a single
schema defines structural and some semantic constraints for names within a
namespace (including the non-namespace). However not every document having
data with namespaces needs to have a schema.
> And what is the advantage of typed vs untyped xml in sql server. Also,
> does Sql server support any other types of schemas?
Untyped XML gives you the advantage of complete flexibity of your structure
and no additional validation cost.
Typed XML gives you semantical assurances over the structure of the data,
provides error detection at compile time in your queries (using static
typing), and can be used for some storage and query optimizations.
SQL Server has only limited support for DTDs and other wise does not support
other types of schemas.
> I'm still slowly going through the books online material, but it'd be
> nice if all these questions are all answered at once.
> Thank you, this is a great usenet group,
> Joyce
> On Jan 24, 8:05 pm, "Michael Rys [MSFT]" <m...@.online.microsoft.com>
> wrote:
>
AdventureWorks inserting records to JobCandidates example
re: AdventureWorks example
Are there source code to how the
HumanResources.JobCandidate
table was created?
(I would like to look at the sample code for INSERTing)
thanks
joyce
What exactly do you want to know about?
Thanks
Michael
PS: I don't think we have sample code for specifically this table...
"joyce chan" <joyceschan@.fastmail.fm> wrote in message
news:1169588888.525240.259000@.j27g2000cwj.googlegr oups.com...
> Hi
> re: AdventureWorks example
> Are there source code to how the
> HumanResources.JobCandidate
> table was created?
> (I would like to look at the sample code for INSERTing)
> thanks
> joyce
>
|||Actually, what I am really confused about is namespace...
So I thought I should take a look at how the JobCandidates table was
created in AdventureWorks.
I understand targetnamespace, and
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
I don't really understand default namespace such as
xmlns="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"
What is the purpose of the def ns?
And also, what is the purpose of the schema collection? And how come a
schema collection can contain multiple schema.
And what is the advantage of typed vs untyped xml in sql server. Also,
does Sql server support any other types of schemas?
I'm still slowly going through the books online material, but it'd be
nice if all these questions are all answered at once.
Thank you, this is a great usenet group,
Joyce
On Jan 24, 8:05 pm, "Michael Rys [MSFT]" <m...@.online.microsoft.com>
wrote:[vbcol=seagreen]
> What exactly do you want to know about?
> Thanks
> Michael
> PS: I don't think we have sample code for specifically this table...
> "joyce chan" <joycesc...@.fastmail.fm> wrote in messagenews:1169588888.525240.259000@.j27g2000cwj.g ooglegroups.com...
>
>
|||See inline below.
Best regards
Michael
"joyce chan" <joyceschan@.fastmail.fm> wrote in message
news:1169736748.697916.238950@.s48g2000cws.googlegr oups.com...
> Actually, what I am really confused about is namespace...
> So I thought I should take a look at how the JobCandidates table was
> created in AdventureWorks.
> I understand targetnamespace, and
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> I don't really understand default namespace such as
> xmlns="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"
> What is the purpose of the def ns?
Default namespaces are just a syntactic convenience in that you do not have
to write a prefix (this is true for XML documents and XQuery, but not XPath
1.0 where no support for default namespace exists, you have to define a
prefix for the query).
Namespaces per se are just scoping mechanisms to scope a name to a space
that can have different semantics associated than the same name in a
different namespace... e.g., river:bank vs finance:bank.
> And also, what is the purpose of the schema collection? And how come a
> schema collection can contain multiple schema.
A schema collection is a meta data object in SQL Server that allows you to
combine multiple schemas in a logical unit to constrain and type an XML data
type instance with. It also introduces a way that allows you to have more
than one version of the same schema within your database. Note that a single
schema defines structural and some semantic constraints for names within a
namespace (including the non-namespace). However not every document having
data with namespaces needs to have a schema.
> And what is the advantage of typed vs untyped xml in sql server. Also,
> does Sql server support any other types of schemas?
Untyped XML gives you the advantage of complete flexibity of your structure
and no additional validation cost.
Typed XML gives you semantical assurances over the structure of the data,
provides error detection at compile time in your queries (using static
typing), and can be used for some storage and query optimizations.
SQL Server has only limited support for DTDs and other wise does not support
other types of schemas.
> I'm still slowly going through the books online material, but it'd be
> nice if all these questions are all answered at once.
> Thank you, this is a great usenet group,
> Joyce
> On Jan 24, 8:05 pm, "Michael Rys [MSFT]" <m...@.online.microsoft.com>
> wrote:
>
sql
Monday, March 19, 2012
Advantages and disadvantages
Code: ( text )
[list]what is the advantages and disadvantages of Ms SQL server and java servletts front-end on the clien end.[list]what is the advantages and disadvantages of Ms Access on the server, connected via JDBC and java on the client end.what is the advantages and disadvantages of HTML on the client end,coupled with SQL server and ODBL on the server end.
My first experience with JDBC (several years ago) left much to be desired. It was simply a Java layer on top of ODBC and was God Awful slow and many ODBC features were not implimented or had some sort of custom implimentation. Simple things like execute calls could not be done in a standard query statement, they had to use a separate exec entry point.
Lately though my experience is MUCH better. The current implimentation I use does not use the ODBC layer and instead goes directly to the SQL dll -- MUCH, MUCH, MUCH faster and as far as I can tell, fully implimented without custom entry points. Oh, by the way, did I tell you it's MUCH faster!
My experience is with CFMX and the JDBC that comes with it. I can round up the version information if you need it but if you are using CFMX, then as long as you are on the latest and greatest, I don't see any disadvantages.
Advanced Transact_SQL
I've a problem. I must convert a query dinamically composed in an ASP
script, in a stored procedure
The Visual Basic code is below.
Could you help me anyway?
SELECT ID,titolo,sottotitolo,data,file FROM tbl_promozioni WHERE
if(new_titolo <> "") then
mySQL=mySQL & "titolo LIKE '%" & new_sottotitolo & "%' AND "
end if
if(new_sottotitolo <> "") then
mySQL=mySQL & "sottotitolo LIKE '%" & new_sottotitolo & AND "
end if
if((da <> "" AND a <> "")) then
mySQL=mySQL & "(((data)>=#"& da & "#) AND ((data)<=#"& a & "#))"
end if
mySQL=trim(mySQL)
' tolgo eventuali AND finali
if(mid(mySQL,len(mySQL)-3,3)="AND" or mid(mySQL,len(mySQL)-3,3)="
AN") then
mySQL=mid(mySQL,1,len(mySQL)-3)
end if
mySQL=mySQL & " order by data DESC"
Thank you very much
Hi
"elisacarli" wrote:
> Hi everyone
> I've a problem. I must convert a query dinamically composed in an ASP
> script, in a stored procedure
> The Visual Basic code is below.
> Could you help me anyway?
> SELECT ID,titolo,sottotitolo,data,file FROM tbl_promozioni WHERE
> if(new_titolo <> "") then
> mySQL=mySQL & "titolo LIKE '%" & new_sottotitolo & "%' AND "
> end if
> if(new_sottotitolo <> "") then
> mySQL=mySQL & "sottotitolo LIKE '%" & new_sottotitolo & AND "
> end if
> if((da <> "" AND a <> "")) then
> mySQL=mySQL & "(((data)>=#"& da & "#) AND ((data)<=#"& a & "#))"
> end if
> mySQL=trim(mySQL)
> ' tolgo eventuali AND finali
> if(mid(mySQL,len(mySQL)-3,3)="AND" or mid(mySQL,len(mySQL)-3,3)="
> AN") then
> mySQL=mid(mySQL,1,len(mySQL)-3)
> end if
> mySQL=mySQL & " order by data DESC"
> Thank you very much
>
Check out http://www.sommarskog.se/dyn-search.html
John
|||in the following your string is not properly closed
if(new_sottotitolo <> "") then
mySQL=mySQL & "sottotitolo LIKE '%" & new_sottotitolo & AND "
end if
this should be
mySQL=mySQL & "sottotitolo LIKE '%" & new_sottotitolo & "%' AND "
futher you are cheking whether the SQL string end with "AND" if true you're
removing it. but if all the three conditions fails "WHERE" clouse will throw
you an error. So try to remove the "WHERE" clouse in the "SELECT" statment is
no condition were met.
Otherwise you can include a dumy condition to avoid the error.
"SELECT ID,titolo,sottotitolo,data,file FROM tbl_promozioni WHERE ID > 0 "
"elisacarli" wrote:
> Hi everyone
> I've a problem. I must convert a query dinamically composed in an ASP
> script, in a stored procedure
> The Visual Basic code is below.
> Could you help me anyway?
> SELECT ID,titolo,sottotitolo,data,file FROM tbl_promozioni WHERE
> if(new_titolo <> "") then
> mySQL=mySQL & "titolo LIKE '%" & new_sottotitolo & "%' AND "
> end if
> if(new_sottotitolo <> "") then
> mySQL=mySQL & "sottotitolo LIKE '%" & new_sottotitolo & AND "
> end if
> if((da <> "" AND a <> "")) then
> mySQL=mySQL & "(((data)>=#"& da & "#) AND ((data)<=#"& a & "#))"
> end if
> mySQL=trim(mySQL)
> ' tolgo eventuali AND finali
> if(mid(mySQL,len(mySQL)-3,3)="AND" or mid(mySQL,len(mySQL)-3,3)="
> AN") then
> mySQL=mid(mySQL,1,len(mySQL)-3)
> end if
> mySQL=mySQL & " order by data DESC"
> Thank you very much
>
Advanced Transact_SQL
I've a problem. I must convert a query dinamically composed in an ASP
script, in a stored procedure
The Visual Basic code is below.
Could you help me anyway?
SELECT ID,titolo,sottotitolo,data,file FROM tbl_promozioni WHERE
if(new_titolo <> "") then
mySQL=mySQL & "titolo LIKE '%" & new_sottotitolo & "%' AND "
end if
if(new_sottotitolo <> "") then
mySQL=mySQL & "sottotitolo LIKE '%" & new_sottotitolo & AND "
end if
if((da <> "" AND a <> "")) then
mySQL=mySQL & "(((data)>=#"& da & "#) AND ((data)<=#"& a & "#))"
end if
mySQL=trim(mySQL)
' tolgo eventuali AND finali
if(mid(mySQL,len(mySQL)-3,3)="AND" or mid(mySQL,len(mySQL)-3,3)="
AN") then
mySQL=mid(mySQL,1,len(mySQL)-3)
end if
mySQL=mySQL & " order by data DESC"
Thank you very muchHi
"elisacarli" wrote:
> Hi everyone
> I've a problem. I must convert a query dinamically composed in an ASP
> script, in a stored procedure
> The Visual Basic code is below.
> Could you help me anyway?
> SELECT ID,titolo,sottotitolo,data,file FROM tbl_promozioni WHERE
> if(new_titolo <> "") then
> mySQL=mySQL & "titolo LIKE '%" & new_sottotitolo & "%' AND "
> end if
> if(new_sottotitolo <> "") then
> mySQL=mySQL & "sottotitolo LIKE '%" & new_sottotitolo & AND "
> end if
> if((da <> "" AND a <> "")) then
> mySQL=mySQL & "(((data)>=#"& da & "#) AND ((data)<=#"& a & "#))"
> end if
> mySQL=trim(mySQL)
> ' tolgo eventuali AND finali
> if(mid(mySQL,len(mySQL)-3,3)="AND" or mid(mySQL,len(mySQL)-3,3)="
> AN") then
> mySQL=mid(mySQL,1,len(mySQL)-3)
> end if
> mySQL=mySQL & " order by data DESC"
> Thank you very much
>
Check out http://www.sommarskog.se/dyn-search.html
John|||in the following your string is not properly closed
if(new_sottotitolo <> "") then
mySQL=mySQL & "sottotitolo LIKE '%" & new_sottotitolo & AND "
end if
this should be
mySQL=mySQL & "sottotitolo LIKE '%" & new_sottotitolo & "%' AND "
futher you are cheking whether the SQL string end with "AND" if true you're
removing it. but if all the three conditions fails "WHERE" clouse will throw
you an error. So try to remove the "WHERE" clouse in the "SELECT" statment i
s
no condition were met.
Otherwise you can include a dumy condition to avoid the error.
"SELECT ID,titolo,sottotitolo,data,file FROM tbl_promozioni WHERE ID > 0 "
"elisacarli" wrote:
> Hi everyone
> I've a problem. I must convert a query dinamically composed in an ASP
> script, in a stored procedure
> The Visual Basic code is below.
> Could you help me anyway?
> SELECT ID,titolo,sottotitolo,data,file FROM tbl_promozioni WHERE
> if(new_titolo <> "") then
> mySQL=mySQL & "titolo LIKE '%" & new_sottotitolo & "%' AND "
> end if
> if(new_sottotitolo <> "") then
> mySQL=mySQL & "sottotitolo LIKE '%" & new_sottotitolo & AND "
> end if
> if((da <> "" AND a <> "")) then
> mySQL=mySQL & "(((data)>=#"& da & "#) AND ((data)<=#"& a & "#))"
> end if
> mySQL=trim(mySQL)
> ' tolgo eventuali AND finali
> if(mid(mySQL,len(mySQL)-3,3)="AND" or mid(mySQL,len(mySQL)-3,3)="
> AN") then
> mySQL=mid(mySQL,1,len(mySQL)-3)
> end if
> mySQL=mySQL & " order by data DESC"
> Thank you very much
>
Advanced Transact_SQL
I've a problem. I must convert a query dinamically composed in an ASP
script, in a stored procedure
The Visual Basic code is below.
Could you help me anyway?
SELECT ID,titolo,sottotitolo,data,file FROM tbl_promozioni WHERE
if(new_titolo <> "") then
mySQL=mySQL & "titolo LIKE '%" & new_sottotitolo & "%' AND "
end if
if(new_sottotitolo <> "") then
mySQL=mySQL & "sottotitolo LIKE '%" & new_sottotitolo & AND "
end if
if((da <> "" AND a <> "")) then
mySQL=mySQL & "(((data)>=#"& da & "#) AND ((data)<=#"& a & "#))"
end if
mySQL=trim(mySQL)
' tolgo eventuali AND finali
if(mid(mySQL,len(mySQL)-3,3)="AND" or mid(mySQL,len(mySQL)-3,3)="
AN") then
mySQL=mid(mySQL,1,len(mySQL)-3)
end if
mySQL=mySQL & " order by data DESC"
Thank you very muchHi
"elisacarli" wrote:
> Hi everyone
> I've a problem. I must convert a query dinamically composed in an ASP
> script, in a stored procedure
> The Visual Basic code is below.
> Could you help me anyway?
> SELECT ID,titolo,sottotitolo,data,file FROM tbl_promozioni WHERE
> if(new_titolo <> "") then
> mySQL=mySQL & "titolo LIKE '%" & new_sottotitolo & "%' AND "
> end if
> if(new_sottotitolo <> "") then
> mySQL=mySQL & "sottotitolo LIKE '%" & new_sottotitolo & AND "
> end if
> if((da <> "" AND a <> "")) then
> mySQL=mySQL & "(((data)>=#"& da & "#) AND ((data)<=#"& a & "#))"
> end if
> mySQL=trim(mySQL)
> ' tolgo eventuali AND finali
> if(mid(mySQL,len(mySQL)-3,3)="AND" or mid(mySQL,len(mySQL)-3,3)="
> AN") then
> mySQL=mid(mySQL,1,len(mySQL)-3)
> end if
> mySQL=mySQL & " order by data DESC"
> Thank you very much
>
Check out http://www.sommarskog.se/dyn-search.html
John|||in the following your string is not properly closed
if(new_sottotitolo <> "") then
mySQL=mySQL & "sottotitolo LIKE '%" & new_sottotitolo & AND "
end if
this should be
mySQL=mySQL & "sottotitolo LIKE '%" & new_sottotitolo & "%' AND "
futher you are cheking whether the SQL string end with "AND" if true you're
removing it. but if all the three conditions fails "WHERE" clouse will throw
you an error. So try to remove the "WHERE" clouse in the "SELECT" statment is
no condition were met.
Otherwise you can include a dumy condition to avoid the error.
"SELECT ID,titolo,sottotitolo,data,file FROM tbl_promozioni WHERE ID > 0 "
"elisacarli" wrote:
> Hi everyone
> I've a problem. I must convert a query dinamically composed in an ASP
> script, in a stored procedure
> The Visual Basic code is below.
> Could you help me anyway?
> SELECT ID,titolo,sottotitolo,data,file FROM tbl_promozioni WHERE
> if(new_titolo <> "") then
> mySQL=mySQL & "titolo LIKE '%" & new_sottotitolo & "%' AND "
> end if
> if(new_sottotitolo <> "") then
> mySQL=mySQL & "sottotitolo LIKE '%" & new_sottotitolo & AND "
> end if
> if((da <> "" AND a <> "")) then
> mySQL=mySQL & "(((data)>=#"& da & "#) AND ((data)<=#"& a & "#))"
> end if
> mySQL=trim(mySQL)
> ' tolgo eventuali AND finali
> if(mid(mySQL,len(mySQL)-3,3)="AND" or mid(mySQL,len(mySQL)-3,3)="
> AN") then
> mySQL=mid(mySQL,1,len(mySQL)-3)
> end if
> mySQL=mySQL & " order by data DESC"
> Thank you very much
>
Sunday, March 11, 2012
Advanced Howto Request for Conditional formatting with Custom Code
Well, I managed to get all the mdx pieces of my problem resolved. Now I
need to solve a tricky conditional formatting problem. Let me provide some
info first and then I'll ask a few questions.
The report I have generated is a very concise matrix. It basically assigns
ranks to failure modes by product family and displays product families side
by side (ascending alphabetically along columns) with failure modes for each
family ascending by rank (rows). A simple ASCII version of the matrix layout:
| product_family
--
rank | failure_mode
yields:
| pfC | pfE | pfF | pfH |
pfJ |
----
1 | mode45 | mode13 | mode94 | mode45 | mode08 |
2 | mode13 | mode26 | mode13 | mode13 | mode45 |
3 | mode77 | mode91 | mode27 | mode74 | mode26 |
4 | mode26 | mode45 | mode12 | mode13 | mode39 |
5 | mode68 | mode94 | mode24 | mode68 | mode27 |
6 | mode94 | mode12 | mode83 | mode94 | mode12 |
The report requestor needs the ability to pick a given product_family, lets
say pfH for now, as a color coding standard. Then the top 10 modes for pfH
will be assigned color codes (background and complementary font) based on a
standard. Based on the standard, matching modes in all product_families are
color coded the same. This has the effect of being able to show where
failure modes in one family fall within all the other families.
I have a function, setcolor() that I can use to set the background (BG) and
font (FT) colors. Now, I need to figure out how to read the modes for a
given family into an array (?) and then pass the array (?) to setcolor(). I
have created a separate hidden table that houses the basis family (parameter
driven) with its modes and I am trying to read that into an array.
I would like to be able to have yet another hidden table in the report
holding 10 rows with BG and FT the way I would like them. These properties
would be read into an array along with the modes for the basis family. Then
I would pass the modes, BG and FT to setcolor() and be fine.
Is it possible to read BG and FT properties of a matrix cell/textbox into an
array in code?
Right now it looks like I'll be hardcoding the BG and FT properties in an
array and then combining these with the modes for our basis family in another
array. From here, I'll have to see how to get this into setcolor().
Does anyone have any recommendations, thoughts or pointers for this.
Thanks!For those that may struggle through something similar...
To summarize, the requirement was to color code a matrix based on a basis
family. The top 10 modes for the basis family need to be used to color code
the modes of all other families. This gives the users an easy visual way to
see how the top modes of one family fall out in the other families.
First I did this all in embedded code as I don't see using this in other
places, if that changes then the code would need to be refactored.
Additionally, there are assuredly other ways of doing this.
Anyway, like I said in the first post, the first thing I had to do was
declare my array. I needed it to be global so I could address it from
different functions, so:
'Declare global 2D array Standard()
Private Shared Standard(10, 3) As String
Then I hard coded an array initialization scheme such that Standard(n,1) had
the background color and Standard(n,2) had the font color. For the moment I
left Standard(n,3) alone:
'Function to Init Standard(), this function must be called separately
before use
Shared Function InitStandard()
Standard(1, 1) = "Navy"
Standard(1, 2) = "White"
Standard(2, 1) = "Cyan"
Standard(2, 2) = "Black"
Standard(3, 1) = "PeachPuff"
Standard(3, 2) = "Black"
Standard(4, 1) = "Honeydew"
Standard(4, 2) = "Black"
Standard(5, 1) = "Black"
Standard(5, 2) = "White"
Standard(6, 1) = "MediumTurquoise"
Standard(6, 2) = "White"
Standard(7, 1) = "Olive"
Standard(7, 2) = "White"
Standard(8, 1) = "Thistle"
Standard(8, 2) = "Black"
Standard(9, 1) = "Lime"
Standard(9, 2) = "Black"
Standard(10, 1) = "Yellow"
Standard(10, 2) = "Black"
End Function
Next, we needed to get our Modes into the array (that is where Standard(n,3)
comes in). So to do this, I wrote a function that is to be used in the
hidden table to get the modes for the basis family, update Standard() and
return the Mode. The basis family is selected by a parameter then the hidden
table returns the family, the Mode, the result of the following function
(basically the Mode again, but I include both columns as a sanity check) and
XRank:
'Function reads in Modes, updates Standard() with Mode and Returns Mode
Shared Function GetModes(ByVal XRank As String, ByVal Mode As String)
Dim idx As Integer
idx = CInt(XRank)
If idx <= 10 Then
Standard(idx, 3) = Mode
End If
Return Mode
End Function
At this point we have read in the Top 10 Modes from the basis family. That
was the hard part. Now, all we need to do is color code the modes in the
result table with all families based on the basis family. For this we will
be calling another function from the Background Color and Color Properties of
the mode textbox in the result matrix:
'Function to Set background color (BG) and font (FT)
Shared Function SetColor(ByVal XRank As String, ByVal Mode As String,
ByVal Param As String) As String
Dim BG As String
Dim FT As String
Dim idx As Integer
Dim i As Integer
InitStandard()
idx = CInt(XRank)
For i = 1 To 10
If Standard(i, 3) = Mode Then
BG = Standard(i, 1)
FT = Standard(i, 2)
Exit For
End If
Next i
Select Case Param
Case "Background"
Return BG
Case "Font"
Return FT
End Select
End Function
Basically, I read in the Mode, loop through Standard(i,3) looking to find a
match and if/when I do hit a match I set BG = Standard(i, 1) and FT =Standard(i, 2) and exit the loop. Note that I must call InitStandard() first
to initialize it befoe I do anything. Without this call the global array is
never initialized. Additionally, I used Case here to determine if I am
setting BG or FG depending on how the function was called. Looking at the
code now, I don't think I need to pass in XRank as I never end up using idx.
Looks like I have a little bit of cleanup left.
Anyway, that wraps it up. To recap, we define a global array, use a
hard-coded array initialization function and a hidden table to populate the
global array, then we read through the array looking for our matching mode to
color code our resultant matrix. All in all not too bad. If I had been
asked to do this in our previous toolset, I would have had to say it was
impossible.
Cheers,
"asnewbie+rs=argh" wrote:
> RS List,
> Well, I managed to get all the mdx pieces of my problem resolved. Now I
> need to solve a tricky conditional formatting problem. Let me provide some
> info first and then I'll ask a few questions.
> The report I have generated is a very concise matrix. It basically assigns
> ranks to failure modes by product family and displays product families side
> by side (ascending alphabetically along columns) with failure modes for each
> family ascending by rank (rows). A simple ASCII version of the matrix layout:
> | product_family
> --
> rank | failure_mode
> yields:
> | pfC | pfE | pfF | pfH | pfJ |
> ----
> 1 | mode45 | mode13 | mode94 | mode45 | mode08 |
> 2 | mode13 | mode26 | mode13 | mode13 | mode45 |
> 3 | mode77 | mode91 | mode27 | mode74 | mode26 |
> 4 | mode26 | mode45 | mode12 | mode13 | mode39 |
> 5 | mode68 | mode94 | mode24 | mode68 | mode27 |
> 6 | mode94 | mode12 | mode83 | mode94 | mode12 |
> The report requestor needs the ability to pick a given product_family, lets
> say pfH for now, as a color coding standard. Then the top 10 modes for pfH
> will be assigned color codes (background and complementary font) based on a
> standard. Based on the standard, matching modes in all product_families are
> color coded the same. This has the effect of being able to show where
> failure modes in one family fall within all the other families.
> I have a function, setcolor() that I can use to set the background (BG) and
> font (FT) colors. Now, I need to figure out how to read the modes for a
> given family into an array (?) and then pass the array (?) to setcolor(). I
> have created a separate hidden table that houses the basis family (parameter
> driven) with its modes and I am trying to read that into an array.
> I would like to be able to have yet another hidden table in the report
> holding 10 rows with BG and FT the way I would like them. These properties
> would be read into an array along with the modes for the basis family. Then
> I would pass the modes, BG and FT to setcolor() and be fine.
> Is it possible to read BG and FT properties of a matrix cell/textbox into an
> array in code?
> Right now it looks like I'll be hardcoding the BG and FT properties in an
> array and then combining these with the modes for our basis family in another
> array. From here, I'll have to see how to get this into setcolor().
> Does anyone have any recommendations, thoughts or pointers for this.
> Thanks!
Tuesday, March 6, 2012
ADOX problem...?
forum I found post about ADOX and this code to rename the tables:
Private Sub RenameTables(ByVal sTextToRemove As String)
Dim i As Integer
Dim dbRename As Database
Dim Connect As New PrivDBEngine
dbRename = Connect.OpenDatabase(tbDBPath.Text)
dbRename.CreateTableDef()
For i = 0 To dbRename.TableDefs.Count - 1
If dbRename.TableDefs(i).Name.Length >= sTextToRemove.Length - 1 Then
If dbRename.TableDefs(i).Name.Substring(0, 9) = sTextToRemove Then
dbRename.TableDefs(i).Name = dbRename.TableDefs(i).Name.Substring(9)
End If
End If
Next i
dbRename.Close()
dbRename = Nothing
MessageBox.Show("Tables in " + tbDBPath.Text + " have been renamed.
Rename Access Tables", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
But it doesn't work because i get an error on Dim dbRename As Database Dim Connect As New PrivDBEngine
What I need to do for this to work?
Thank you!
The code is for DAO so the first thing you need to do is add the DAO 3.6 COM library reference to your application (Project...Add Reference).
Then, I would declare those objects and fully qualify the types using the library name:
Dim dbRename As DAO.Database
Dim Connect As DAO.PrivDBEngine
|||
Hi,
Please do the following process to add the required references,
1. Right click on your project in Solution explorer and select Add references...
2. Select COM tab and search for following two libraries and add it,
- Microsoft ADO Ext. 2.8 for DLL and Security
- Microsoft DAO 3.6 Object Library
To see those dlls in References section,
Select Project -> Show all files
So under the References the following two dlls will be shown:
1. ADOX
2. DAO
The code does the following things in MS Access
1. Create database
2. Create a table
3. Rename a table
[The following code creates TestDB.mdb in C:\ and create a table named MyTable. Then it renamed as "MyNewNameTable"]
Imports ADOX
Imports DAO
Public Class Form1
Dim catalog As Catalog = New ADOX.Catalog()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CreateDatabaseAndTable("TestDB.mdb", "MyTable")
RenameTables("MyTable", "MyNewNameTable")
End Sub
Private Sub CreateDatabaseAndTable(ByVal databasename As String, ByVal tablename As String)
catalog.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\" + databasename + ";" & _
"Jet OLEDB:Engine Type=5")
Console.WriteLine("Database Created Successfully")
Dim firsttable As Table = New Table()
firsttable.Name = tablename
firsttable.Columns.Append("CustID", ADOX.DataTypeEnum.adInteger)
firsttable.Columns.Append("CustName", ADOX.DataTypeEnum.adVarWChar, 30)
firsttable.Keys.Append("PK_CustID", 1, "CustID")
catalog.Tables.Append(firsttable)
firsttable = Nothing
catalog = Nothing
End Sub
Private Sub RenameTables(ByVal sOldName As String, ByVal sNewName As String)
Dim i As Integer
Dim databasepath = "C:\TestDB.mdb"
Dim dbRename As Database
Dim Connect As New PrivDBEngine
dbRename = Connect.OpenDatabase(databasepath)
dbRename.CreateTableDef()
For i = 0 To dbRename.TableDefs.Count - 1
Try
If dbRename.TableDefs(i).Name = sOldName Then
dbRename.TableDefs(i).Name = sNewName
End If
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Next i
dbRename.Close()
dbRename = Nothing
MessageBox.Show("Tables in " & databasepath & " have been renamed. Rename Access Tables")
End Sub
End Class
For further information, please refer,
http://www.4guysfromrolla.com/webtech/013101-1.shtml
http://www.4guysfromrolla.com/webtech/tips/t030802-1.shtml
http://www.microsoft.com/technet/prodtechnol/sql/70/proddocs/msjet/jetch02.mspx?mfr=true
http://www.codeguru.com/vb/gen/vb_database/microsoftaccess/article.php/c5149/
HTH,
ADOMD.NET DbProviderFactory
Moved it from BCL forum to Data Access and Storage forum where is more appropriate.
Thank you for your active participation!
ADOMD.NET AdomdDataReader + ASP.NET 2.0 gridview?
Anybody had any success with populating an ASP.NET 2.0 gridview using ADOMD.NET AdomdDataReader?
I am trying the following code:
Dim oSb AsNew StringBuilder
Dim sMDX AsString
Dim sCnnString AsString = "DataSource=localhost"
Dim oAdoMdCnn As AdomdConnection
Dim oAdoMdCmd As AdomdCommand
Dim oAdoMdRdr As AdomdDataReader
'...build oSb
sMDX = oSb.ToString
sCnnString = "DataSource=localhost"
oAdoMdCnn = New AdomdConnection(sCnnString)
oAdoMdCnn.Open()
oAdoMdCmd = New AdomdCommand(sMDX, oAdoMdCnn)
oAdoMdRdr = oAdoMdCmd.ExecuteReader()
Dim oTable AsNew DataTable
oTable.Load(oAdoMdRdr)
gvResults.DataSource = oTable
gvResults.DataBind()
I get an error message at oTable.Load(oAdoMdRdr) that says:
"Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints."
This gives a couple of options for datasets, but no mention of datareaders nevertheless AdomdDataReaders. I have tried "oTable.Constraints.Clear()" to eliminate any constraints, but no luck. I don't want any keys or constraints. I don't need any writeback so I think using a dataset may be more overhead than necessary.
Anyone?
Keehan
hello Keehan,
it's not competely clear to me what the problem is here (it might be specific to the query result, so if you can provide a query against Adventure Works sample that this error happens with, then perhaps it could shed some light here).
however, you could also try something like:
Dim oTable As New DataTable()
// where cmd is the command to execute
Using adapter As New AdomdDataAdapter(cmd)
adapter.Fill(oTable)
End Using
and see if that works to populate the table.
hope this helps,
|||Mary,
I tried using AdomdDataAdapter as you recommended and I get an even weirder message:
InvalidOperationException was unhandled by user code
“The connection cannot be used while an XmlReader object is open.”
While debugging I found that if I look at the properties of adapter, the Message attribute of the SelectCommand property says:
Message"Unable to cast object of type 'Microsoft.AnalysisServices.AdomdClient.AdomdCommand' to type 'System.Data.Common.DbCommand'."String
And the StackTrace attribute says:
StackTrace"at System.Data.Common.DbDataAdapter.get_SelectCommand()"String
I know the MDX query itself works fine.I’m capturing it to a text box and then I can run it from Management Studio.I’m just having trouble getting the plumbing of this to work.Any other ideas?
If anyone has a sample using ADOMD.NET to populate a gridview I would be grateful.
Cheers,
Keehan
hello Keehan,
actually, the error you observe indicates that a data reader (or xml reader) were not closed. It means that somewhere in the code there is a call to cmd.ExecuteReader(), but the returned reader is never closed or disposed. It is very impornant that the reader is closed otherwise the error would be thrown just as the one you observed. (so it is good idea to work with reader with Using or try-finally to make sure it's always closed/disposed)
the following code snippet works fine for me, populating the DataTable (resultsInTable) with data fine:
Dim resultsInTable As New DataTable()
Using con As New AdomdConnection()
con.ConnectionString = "datasource=localhost;catalog=Adventure Works DW;"
con.Open()Dim cmd As AdomdCommand
cmd = con.CreateCommand()
cmd.CommandText = "select measures.members on 0, [Customer].[Customer Geography].[Country].members on 1 from [Adventure Works]"Using adapter As New AdomdDataAdapter(cmd)
adapter.Fill(resultsInTable)
End UsingEnd Using
so, i'm not sure why it would not work for you. maybe something else happens when different data comes back (obviously when different query is executed), but i couldn't tell not knowing more specifics.
also, it looks like the GridView with AutoGenerateColumns=true, has some limitations as to how the columns of type System.Object are handled - i think they are not added to grid view (or maybe i was doing something wrong - as i'm not too familiar with the System.Web.UI.WebControls.GridView). so it might be that for the example above one would have to write some more code to actually create columns in the grid view for the un-bindable column types, or do some other things: like tweaking the data table converting the un-bindable data types to strings or something else...
all in all for the sample above the following code worked for me (note code is not too clean, and is just intended as an illustration; i'm also not too familiar with VB):
Imports Microsoft.AnalysisServices.AdomdClient
Imports System.DataPartial Class _Default
Inherits System.Web.UI.PageDim gv As GridView
Protected Sub Page_Load1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim resultsInTable As New DataTable()
Using con As New AdomdConnection()
con.ConnectionString = "datasource=localhost;catalog=Adventure Works DW;"
con.Open()Dim cmd As AdomdCommand
cmd = con.CreateCommand()
cmd.CommandText = "select measures.members on 0, [Customer].[Customer Geography].[Country].members on 1 from [Adventure Works]"Using adapter As New AdomdDataAdapter(cmd)
adapter.Fill(resultsInTable)
End UsingEnd Using
' because looks like GridView has limitations and only supports certain column types (and not not object typed one for autogenerate columns)
' let's do the following : for each not supported column type - add a string typed columnDim numberColumns As Integer
numberColumns = resultsInTable.Columns.Count - 1
For i As Integer = 0 To numberColumnsDim current As DataColumn
current = resultsInTable.Columns.Item(i)
Dim colName As StringDim baseName = "column_"
'you might need to be smarter about picking the base of the column name,
'as column names based on it must not be present in the table alreadyIf BaseDataList.IsBindableType(current.DataType) = False Then
colName = current.ColumnName
current.ColumnName = baseName + i.ToString() ' might need to be smarter and check if the name already exists in the table
Dim col As New DataColumn(colName, System.Type.GetType("System.String"), "Convert(" + current.ColumnName + ", 'System.String')")
resultsInTable.Columns.Add(col)
End If
Next igv.DataSource = resultsInTable
gv.DataBind()End Sub
Protected Sub form1_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Init
gv = New GridView()
gv.AutoGenerateColumns = True
form1.Controls.Add(gv)End Class
hope this helps,
|||Hello Mary,
i was having the problem that when a i bound the return of an mdx command to a gridView, the columns simply doesn′t appear.
i searched at the web and i found your solution, i'm just interesting to know if there is another way to show the columns in the gridView, without handling them as you did, i mean if there is another component, another alternative, i know that this solutions works ( i tested it :P ) , but maybe there is another way, and since your post was made quite a long time, maybe you or other person, have another solution.
Thanx.|||
hello,
unfortunatelly, i don't have more info on this. I would suggest you to post a question on "Data Presentation Controls" on ASP.NET forum (http://forums.asp.net/24/ShowForum.aspx), and ask about the support for columns of System.Object type with AutoGenerateColumns=true. Perhaps there are other control(s), or maybe there are some settings that can make the GridView work in this scenario. Hopefully they would be able to answer.
hope this helps,
|||You need to turn off constraints at the DataSet level. You have simply tried to clear existing constraints at the table level.
Here's a C# example
DataSet dataSet = new DataSet(); // Create a dataset
dataSet.EnforceConstraints = false; // turn off constraints
dataSet.Tables.Add("Results"); // Add an arbitary table
dataSet.Tables["Results"].Load(reportDataReader); // Load the ADOMD reader into the table
You will then be able to bind the 'Results' table to a gridview.
Hope this helps
Sacha Tomey
Blog - http://blogs.adatis.co.uk/blogs/sachatomey
Consultancy - http://www.adatis.co.uk
ADOMD.NET AdomdDataReader + ASP.NET 2.0 gridview?
Anybody had any success with populating an ASP.NET 2.0 gridview using ADOMD.NET AdomdDataReader?
I am trying the following code:
Dim oSb As New StringBuilder
Dim sMDX As String
Dim sCnnString As String = "DataSource=localhost"
Dim oAdoMdCnn As AdomdConnection
Dim oAdoMdCmd As AdomdCommand
Dim oAdoMdRdr As AdomdDataReader
'...build oSb
sMDX = oSb.ToString
sCnnString = "DataSource=localhost"
oAdoMdCnn = New AdomdConnection(sCnnString)
oAdoMdCnn.Open()
oAdoMdCmd = New AdomdCommand(sMDX, oAdoMdCnn)
oAdoMdRdr = oAdoMdCmd.ExecuteReader()
Dim oTable As New DataTable
oTable.Load(oAdoMdRdr)
gvResults.DataSource = oTable
gvResults.DataBind()
I get an error message at oTable.Load(oAdoMdRdr) that says:
"Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints."
This gives a couple of options for datasets, but no mention of datareaders nevertheless AdomdDataReaders. I have tried "oTable.Constraints.Clear()" to eliminate any constraints, but no luck. I don't want any keys or constraints. I don't need any writeback so I think using a dataset may be more overhead than necessary.
Anyone?
Keehan
hello Keehan,
it's not competely clear to me what the problem is here (it might be specific to the query result, so if you can provide a query against Adventure Works sample that this error happens with, then perhaps it could shed some light here).
however, you could also try something like:
Dim oTable As New DataTable()
// where cmd is the command to execute
Using adapter As New AdomdDataAdapter(cmd)
adapter.Fill(oTable)
End Using
and see if that works to populate the table.
hope this helps,
|||Mary,
I tried using AdomdDataAdapter as you recommended and I get an even weirder message:
InvalidOperationException was unhandled by user code
“The connection cannot be used while an XmlReader object is open.”
While debugging I found that if I look at the properties of adapter, the Message attribute of the SelectCommand property says:
Message"Unable to cast object of type 'Microsoft.AnalysisServices.AdomdClient.AdomdCommand' to type 'System.Data.Common.DbCommand'."String
And the StackTrace attribute says:
StackTrace"at System.Data.Common.DbDataAdapter.get_SelectCommand()"String
I know the MDX query itself works fine.I’m capturing it to a text box and then I can run it from Management Studio.I’m just having trouble getting the plumbing of this to work.Any other ideas?
If anyone has a sample using ADOMD.NET to populate a gridview I would be grateful.
Cheers,
Keehan
hello Keehan,
actually, the error you observe indicates that a data reader (or xml reader) were not closed. It means that somewhere in the code there is a call to cmd.ExecuteReader(), but the returned reader is never closed or disposed. It is very impornant that the reader is closed otherwise the error would be thrown just as the one you observed. (so it is good idea to work with reader with Using or try-finally to make sure it's always closed/disposed)
the following code snippet works fine for me, populating the DataTable (resultsInTable) with data fine:
Dim resultsInTable As New DataTable()
Using con As New AdomdConnection()
con.ConnectionString = "datasource=localhost;catalog=Adventure Works DW;"
con.Open()Dim cmd As AdomdCommand
cmd = con.CreateCommand()
cmd.CommandText = "select measures.members on 0, [Customer].[Customer Geography].[Country].members on 1 from [Adventure Works]"Using adapter As New AdomdDataAdapter(cmd)
adapter.Fill(resultsInTable)
End UsingEnd Using
so, i'm not sure why it would not work for you. maybe something else happens when different data comes back (obviously when different query is executed), but i couldn't tell not knowing more specifics.
also, it looks like the GridView with AutoGenerateColumns=true, has some limitations as to how the columns of type System.Object are handled - i think they are not added to grid view (or maybe i was doing something wrong - as i'm not too familiar with the System.Web.UI.WebControls.GridView). so it might be that for the example above one would have to write some more code to actually create columns in the grid view for the un-bindable column types, or do some other things: like tweaking the data table converting the un-bindable data types to strings or something else...
all in all for the sample above the following code worked for me (note code is not too clean, and is just intended as an illustration; i'm also not too familiar with VB):
Imports Microsoft.AnalysisServices.AdomdClient
Imports System.DataPartial Class _Default
Inherits System.Web.UI.PageDim gv As GridView
Protected Sub Page_Load1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim resultsInTable As New DataTable()
Using con As New AdomdConnection()
con.ConnectionString = "datasource=localhost;catalog=Adventure Works DW;"
con.Open()Dim cmd As AdomdCommand
cmd = con.CreateCommand()
cmd.CommandText = "select measures.members on 0, [Customer].[Customer Geography].[Country].members on 1 from [Adventure Works]"Using adapter As New AdomdDataAdapter(cmd)
adapter.Fill(resultsInTable)
End UsingEnd Using
' because looks like GridView has limitations and only supports certain column types (and not not object typed one for autogenerate columns)
' let's do the following : for each not supported column type - add a string typed columnDim numberColumns As Integer
numberColumns = resultsInTable.Columns.Count - 1
For i As Integer = 0 To numberColumnsDim current As DataColumn
current = resultsInTable.Columns.Item(i)
Dim colName As StringDim baseName = "column_"
'you might need to be smarter about picking the base of the column name,
'as column names based on it must not be present in the table alreadyIf BaseDataList.IsBindableType(current.DataType) = False Then
colName = current.ColumnName
current.ColumnName = baseName + i.ToString() ' might need to be smarter and check if the name already exists in the table
Dim col As New DataColumn(colName, System.Type.GetType("System.String"), "Convert(" + current.ColumnName + ", 'System.String')")
resultsInTable.Columns.Add(col)
End If
Next igv.DataSource = resultsInTable
gv.DataBind()End Sub
Protected Sub form1_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Init
gv = New GridView()
gv.AutoGenerateColumns = True
form1.Controls.Add(gv)End Class
hope this helps,
|||Hello Mary,
i was having the problem that when a i bound the return of an mdx command to a gridView, the columns simply doesn′t appear.
i searched at the web and i found your solution, i'm just interesting to know if there is another way to show the columns in the gridView, without handling them as you did, i mean if there is another component, another alternative, i know that this solutions works ( i tested it :P ) , but maybe there is another way, and since your post was made quite a long time, maybe you or other person, have another solution.
Thanx.|||
hello,
unfortunatelly, i don't have more info on this. I would suggest you to post a question on "Data Presentation Controls" on ASP.NET forum (http://forums.asp.net/24/ShowForum.aspx), and ask about the support for columns of System.Object type with AutoGenerateColumns=true. Perhaps there are other control(s), or maybe there are some settings that can make the GridView work in this scenario. Hopefully they would be able to answer.
hope this helps,
|||You need to turn off constraints at the DataSet level. You have simply tried to clear existing constraints at the table level.
Here's a C# example
DataSet dataSet = new DataSet(); // Create a dataset
dataSet.EnforceConstraints = false; // turn off constraints
dataSet.Tables.Add("Results"); // Add an arbitary table
dataSet.Tables["Results"].Load(reportDataReader); // Load the ADOMD reader into the table
You will then be able to bind the 'Results' table to a gridview.
Hope this helps
Sacha Tomey
Blog - http://blogs.adatis.co.uk/blogs/sachatomey
Consultancy - http://www.adatis.co.uk
Adodb.field error 80020009 in my code
I really don't find the bug in my code. It returns Adodb.field error '80020009'. I tried various things but it don't works. Can U look at my code and find the bug....
-------------------
My connection object is 'dbconn'
My object query is 'rssqlselect_clients'
---------------------
<form name="monform">
<select name="listeA" onchange=changeliste()>
<option value=0>Choisit une liste</option>
<% rssqlselect_clients.moveFirst
while not rssqlselect_clients.eof %>
<% while not t > c %>
<option value=<%= t %>>Liste <%
response.write rssqlselect_clients("nomclient")
%> </option>
<%
t = t + 1
wend %>
<%rssqlselect_clients.moveNext
wend
rssqlselect_clients.close
Dbconn.close%>
------------
Thank U very much.
BaRRonWhat line of script is generating your error?
Saturday, February 25, 2012
ADODB to textBox
First time poster, I am using MS Access and I have used the following code to get some data. It is as follows:
Code Snippet
Private Sub FillGUI()
On Error Resume Next
Dim myRS2 As New ADODB.Recordset
myRS2.ActiveConnection = CurrentProject.Connection
myRS2.CursorType = adOpenDynamic
myRS2.LockType = adLockOptimisticd
myRS2.Open "SELECT E.SSN, E.LNAME, SUM(W.HOURS) FROM EMPLOYEE E, WORKS_ON W WHERE (E.SSN = W.ESSN)GROUP BY E.SSN, E.LNAME HAVING(SUM(HOURS)) < 40"
MsgBox (myRS2.GetString)
myRS2.MoveFirst
End Sub
and I have the following output:
http://www.angelfire.com/oh5/ohiostate120/untitled1.JPGThis is what I want. However I need this to be in a text box so I have the following code:
Code Snippet
Private Sub FillGUI()
On Error Resume Next
Dim myRS2 As New ADODB.Recordset
myRS2.ActiveConnection = CurrentProject.Connection
myRS2.CursorType = adOpenDynamic
myRS2.LockType = adLockOptimisticd
myRS2.Open "SELECT E.SSN, E.LNAME, SUM(W.HOURS) FROM EMPLOYEE E, WORKS_ON W WHERE (E.SSN = W.ESSN)GROUP BY E.SSN, E.LNAME HAVING(SUM(HOURS)) < 40"
Me.txtEmployee.SetFocus
Me.txtEmployee.Text = myRS2.GetString
myRS2.MoveFirst
End Sub
And i get this:
http://www.angelfire.com/oh5/ohiostate120/untitled2.JPG
How can I get the text box format to look like the msgbox format? Thanks.........
This is not an SSIS question.You might try asking in the "Where is the forum for...?" forum to see if someone there can direct you to the correct place to ask your Access question.
Forum: http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=881&SiteID=1
Thanks,
Phil Brammer|||Yeah I thought I put it in the wrong place. Thanks
ADODB fill recrodset with stored proc
recordset. Code goes something like:
Set SQLCmd = New ADODB.Command
Set SQLCmd.ActiveConnection = SQLConn
Set rs = New ADODB.Recordset
Set rs.ActiveConnection = SQLConn
rs.CursorType = adOpenForwardOnly
SQLCmd.CommandText = "usp_RPT_PForm_SetWhereTableBooks"
SQLCmd.CommandType = adCmdStoredProc
'*** Set up parameters
SQLCmd.Parameters.Refresh
SQLCmd.Parameters(1) = "aaa"
…
SQLCmd.Parameters(6) = 0
Set rs = SQLCmd.Execute
The proc usp_RPT_PForm_SetWhereTableBooks should returns a recordset
Pre tests:
I know the connection is active because when I call
SQLCmd.Parameters.Refresh the parameter list (of 6 items) are created.
I have copied the parameters into the sql query analyzer and records are
returned
The problem is that the recordset is not being filled
Can you tell me what I am missing please.
Thanks in advance,
Stewart RogersDo you have "Set NoCOunt On"
at the beginning of your Stored Proc '
If Not, add it and try again...
"Datasort" wrote:
> I have a ADODB recordset problem. I want to use a stored proc to retrieve
a
> recordset. Code goes something like:
>
> Set SQLCmd = New ADODB.Command
> Set SQLCmd.ActiveConnection = SQLConn
> Set rs = New ADODB.Recordset
> Set rs.ActiveConnection = SQLConn
> rs.CursorType = adOpenForwardOnly
>
> SQLCmd.CommandText = "usp_RPT_PForm_SetWhereTableBooks"
> SQLCmd.CommandType = adCmdStoredProc
> '*** Set up parameters
> SQLCmd.Parameters.Refresh
> SQLCmd.Parameters(1) = "aaa"
> …
> SQLCmd.Parameters(6) = 0
> Set rs = SQLCmd.Execute
> The proc usp_RPT_PForm_SetWhereTableBooks should returns a recordset
> Pre tests:
> I know the connection is active because when I call
> SQLCmd.Parameters.Refresh the parameter list (of 6 items) are created.
> I have copied the parameters into the sql query analyzer and records are
> returned
> The problem is that the recordset is not being filled
> Can you tell me what I am missing please.
> Thanks in advance,
> Stewart Rogers
>|||try this:
Dim rs As Adodb.Recordset
Set rs = new ADODB.Recordset
SQLConn.usp_Rpt_PFrom_SetWhereTableBooks "aaa", rs
I bet that works.
Greg Jackson
Portland, OR|||That did it ... Thanks!!! Can you tell me why it works with nocount on?
"CBretana" wrote:
> Do you have "Set NoCOunt On"
> at the beginning of your Stored Proc '
> If Not, add it and try again...
>
> "Datasort" wrote:
>|||Datasort...
Yes, what's going on is that SQL Server sends the Record count information
ahead of the actual recordset... and ADO is not smart enough to tell the
difference, so it's trying to "Read" the record count info as your recordset
,
and failing... It couldn' be coded to figure this out, because ADO 2.x added
functionality to handle multiple recordsets in one call to the server.
There's a method (on the RecordSet Object) in ADO called .NextRecordset, tha
t
moves to the next one in the sequence, until it retruns null when you call i
t
on the last one.
"Datasort" wrote:
> That did it ... Thanks!!! Can you tell me why it works with nocount on?
> "CBretana" wrote:
>|||And, obviously, adding Set NoCount On, removes this information from the TDS
(Tabular Data Stream), and then all that's sent backto ADO Is the actual
recordset...
"Datasort" wrote:
> That did it ... Thanks!!! Can you tell me why it works with nocount on?
> "CBretana" wrote:
>|||Odd, horribly odd!
That sounds like a bug since the record count is not returned (or was not
returned) as a recordset, it is returned as a message AFAIK. Further, the
record count is returned after the requested recordset, not before since it
doesn't know the count until it has returned the rerdorset.
So, I would prefer to see this regarded as a BIG BAD BUG!
Comments?
- Tim
"CBretana" <cbretana@.areteIndNOSPAM.com> wrote in message
news:C6A14044-735D-4DD7-802D-1BB719A4A40F@.microsoft.com...
> Datasort...
> Yes, what's going on is that SQL Server sends the Record count information
> ahead of the actual recordset... and ADO is not smart enough to tell the
> difference, so it's trying to "Read" the record count info as your
> recordset,
> and failing... It couldn' be coded to figure this out, because ADO 2.x
> added
> functionality to handle multiple recordsets in one call to the server.
> There's a method (on the RecordSet Object) in ADO called .NextRecordset,
> that
> moves to the next one in the sequence, until it retruns null when you call
> it
> on the last one.
> "Datasort" wrote:
>|||this is common and well documented behavior in ado
GAJ|||So its a "feature" then?
"pdxJaxon" <GregoryAJackson@.Hotmail.com> wrote in message
news:%23nc7lqYKFHA.3420@.tk2msftngp13.phx.gbl...
> this is common and well documented behavior in ado
>
> GAJ
>
adodb connections to a linked server
I'd like to create an ado connection to my linked server called Prob_Schd on
a machine called pccn-nt.
When I use the code below I recieve an error of the type ' Invalid
connection string attribute'. Would someone show me how to create an ado
connection to a linked server?
Thanks,
Chieko
dim oConn, strConn
Set oConn = Server.CreateObject("ADODB.Connection")
strConn = "provider=SQLOLEDB; Datasource=Prob_Schd; Initial Catalog=null
trusted_Connection=yes "
oConn.Open strConn
set GetDataConnection = oConnADO doesn't know anything about SQL Server's linked servers. You could
connect locally, and then execute queries like adoConnObject.Execute("SELECT
* FROM Prob_Schd.pubs.dbo.authors") or, you could make an OLEDB connection
directly to the linked server.
The specific error you are getting is because the "Datasource" attribute
you've used should have a space, "Data Source"... but I'm pretty sure ADO
will still be unable to find that server unless it is in the hosts file on
the machine (in other words, it doesn't care if that's a linked server in
SQL Server).
"Chieko Kuroda" <ckuroda@.med.unc.edu> wrote in message
news:O2OVMHuzDHA.3520@.tk2msftngp13.phx.gbl...
quote:
> Hello,
> I'd like to create an ado connection to my linked server called Prob_Schd
on
quote:
> a machine called pccn-nt.
> When I use the code below I recieve an error of the type ' Invalid
> connection string attribute'. Would someone show me how to create an ado
> connection to a linked server?
> Thanks,
> Chieko
>
> dim oConn, strConn
> Set oConn = Server.CreateObject("ADODB.Connection")
> strConn = "provider=SQLOLEDB; Datasource=Prob_Schd; Initial
Catalog=null
quote:
> trusted_Connection=yes "
> oConn.Open strConn
> set GetDataConnection = oConn
>
ADODB connection with SQL2000SP3
the way it being done is (c++):
ADODB::_ConnectionPtr m_dbConn;
ADODB::_RecordsetPtr m_dbRst;
m_dbConn.CreateInstance(__uuidof(ADODB::Connection ));
m_dbRst.CreateInstance( __uuidof( ADODB::Recordset ));
m_dbConn->ConnectionString=( L"DSN=mydsn" );
m_dbConn->Open("","sa","",-1);
lately after installing SP3 over SQL2000, it was impossible to connect
- the error message showed: login failed for user 'null)'. reason: not
associated with a trusted sql server connection.
so i changed the connection string to:
m_dbConn-> ConnectionString =(L"DSN=mydsn; UID=sa; PWD=;");
m_dbConn->Open("","","",-1);
and now it works !!
what is the reason for that ?
what in sql SP3 interrupt for this kind of connection ?
what is the difference ?liorh (liorhal@.gmail.com) writes:
> my code is using ADODB connection to connect to SQL (Virtual) Server.
> the way it being done is (c++):
> ADODB::_ConnectionPtr m_dbConn;
> ADODB::_RecordsetPtr m_dbRst;
> m_dbConn.CreateInstance(__uuidof(ADODB::Connection ));
> m_dbRst.CreateInstance( __uuidof( ADODB::Recordset ));
> m_dbConn->ConnectionString=( L"DSN=mydsn" );
> m_dbConn->Open("","sa","",-1);
> lately after installing SP3 over SQL2000, it was impossible to connect
> - the error message showed: login failed for user 'null)'. reason: not
> associated with a trusted sql server connection.
> so i changed the connection string to:
> m_dbConn-> ConnectionString =(L"DSN=mydsn; UID=sa; PWD=;");
> m_dbConn->Open("","","",-1);
> and now it works !!
> what is the reason for that ?
> what in sql SP3 interrupt for this kind of connection ?
> what is the difference ?
Since I don't know what is in that DSN, I would have to guess a bit.
Then again, I never liked DSNs. Anyway, my guess is that since SP3
was very focused on security, it may be that since you did not provide
a password, there is now a default for Windows authentication.
Anyway, running a system with a blank password for 'sa' is extremely
poor practice. So is it for that matter, to use sa to connect to SQL
Server from an application.
--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp