Showing posts with label dropped. Show all posts
Showing posts with label dropped. Show all posts

Friday, March 30, 2012

Losing temporal tables

Hi, i want to know if there's any particular reason why a temporal
table can be dropped before closing the session.
I'm having the following problem: i create the temp table when a form
of my application is created, work with it and then drop it on the
form's close event.
It works fine most of the time, but from time to time the table seems
to be dropped before i close the form because i'm having a: #MyTable
doesn't exists error message.
Any ideas?
Working against SQL2K, W2K Server, from a W2K Pro machine.
Thanx
If your connection is getting dropped at any time you will loose the temp
table. Temp tables are really designed for a brief life span. If you need
to hold certain information for long periods of time like that you may want
to consider using real tables. Or better yet maybe a RS on the client.
Andrew J. Kelly SQL MVP
"Guillermo Casta?o A" <guillermoc74@.hotmail.com> wrote in message
news:9350d78d.0409170946.33db2291@.posting.google.c om...
> Hi, i want to know if there's any particular reason why a temporal
> table can be dropped before closing the session.
> I'm having the following problem: i create the temp table when a form
> of my application is created, work with it and then drop it on the
> form's close event.
> It works fine most of the time, but from time to time the table seems
> to be dropped before i close the form because i'm having a: #MyTable
> doesn't exists error message.
> Any ideas?
> Working against SQL2K, W2K Server, from a W2K Pro machine.
> Thanx

Monday, March 26, 2012

Looping through SQLDataSouce in a Function

Hi All,

Thanks for looking at the post. Here is what I am trying to do:

Lets say I have dragged and dropped a new SqlDataSource onto the page and called it SQLDataSource2

Now, in a function that happens afterload:

ProtectedSub Partners_afterLoad(ByVal senderAsObject,ByVal eAs System.EventArgs)

I want to be able to loop through that SQLDataSource2, and pull a value to compare.

In classic ASP it would be something like:

'Move to the first record
SQLDatasource.MoveFirst

'Loop through Recordset
While Not SQLDataSource2.Eof

'Do compare of the Field MyValue
If SQLDataSource2("MyValue")=27 Then Reponse.Write "Hit on # 27"

'Move to Next Record
SQLDatasource.MoveNext

'End the loop
Wend

My questions are as follows:

1) Do I need to define the Datasource in the function, or can I use the one that VWD2005 helped me to define.

2) How can I loop throught that Datasource (Recordset) in a function.

Any and all help appreciated--Code examples will make me your best friend.

Rather than loop through the entire dataset, I'd use the power of the SQL engine to speed things up a little.

There's a property called "filterexpression". I'd filter the dataset to just return a single row if it exists, and no rows if it doesnt, and you can very quickly check for the existance of a row or not.

Here's an article describing how to use the .filterexpression property, you can combine it with .filterparamaters.

You can access the same property from the codebehind using the Sqldatasource2.filterexpression and SqlDatasource2.filterparamaters method.

http://www.aspnetpro.net/newsletterarticle/2003/11/asp200311ss_l/asp200311ss_l.asp

|||

You can do much of the same thing in ASPX, but the sqldatasource control really wasn't designed for that type of thing. Try the sqlconnection, sqlcommand, and the datareader classes, and it'll be darn near what you are used to.

dim conn as new sqlconnection("{Connection string here}")

conn.open

dim cmd as new sqlcommand("SELECT whatever FROM whereever",conn)

dim dr as datareader=cmd.executedatareader

while dr.read

if dr("whatever")=some value then

' Do something here

end if

end while

dr.close

conn.close

|||

You might even be able to do (I have never tried this, so it might not work)

ForEach drAs DataRowInCType(SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView).ToTable.Rows

if dr("whatever")=some value then

' Do something

end if

Next

|||

Thanks for the reply Freakyuno, unfortunately I do have to loop through the recordset since I am ultimately trying to prepropulate checkboxes from a different table, not just checking to see if the records exists.

Thanks for the link!

|||

Motley!

You are the man! Here was the final code I used:

ForEach drAs Data.DataRowInCType(SqlDataSource2.Select(DataSourceSelectArguments.Empty), Data.DataView).ToTable.Rows

Not sure why I had to do the Data.DataRow thing--but that's what it wanted.

Again, thanks!

|||

Probably because you didn't have something like

imports system.data

at the top of your script, sorry, I normally have that.

|||

Probably because you didn't have something like

imports system.data

at the top of your script, sorry, I normally have that.

There might be a better way of doing it, but that's the first way I came up with. If anyone knows of an easier way, I'd like to hear it too :-)

sql