Showing posts with label piece. Show all posts
Showing posts with label piece. Show all posts

Monday, March 26, 2012

Read single piece of data from SqlDataSource to a variable?

First I want to say thanks to the folks how have helped me over the past week or two.

I'm missing a crucial piece of insight. How do I read a single piece of data from a SqlDataSource which only hold one row of data into a declared variable?

string zUserName = SqlDataSource.(get the value in the row that is labeled UserName)

It really doesn't matter to me whether it is an SqlDataSource or some other data container that hold the data I've selected. My goal is to be able to read some data from some predefined datasource into a declared variable.

If I am approaching this problem in the wrong way any advice or article links you could give me would be grealy appreciate.

Thanks, Bill

It's not really meant to do that, but you CAN if you want to by binding the datasource to a hidden field, telling the hidden field to databind, and then picking up its value (Optionally resetting the hidden field to nothing again).

Really want you want is the sqlconnection and sqlcommand for that type of work. SqlDataSource is for populating UI controls with databinding.

Tuesday, March 20, 2012

re: cursor + rounding?

Hi Guys,

I've created a cursor inside a function. When I break it down and execute the code piece by piece, no problem. However, try and parse it together and I get an error - 'Mixing old and new syntax is not allowed?' Something to do with the return statements? as I can alter the function to a procedure and it parses fine. Anyone come across this before?

Also, the values are being rounded when putting them into the cursor, even though I've declared the variables the cursor uses specifically as decimal? How can I get around this please?

Cheers,

Michelle

Michelle:

Can you describe what you are doing? This sounds rather vague.

|||

Blast, it didn't post. Umm, I've sorted the first problem, and I think I may have the answer to the second one. Will give it a go and let you know. Thanks for your help!

Cheers,

Michelle

|||

OK, both of those problems fixed. Should have been

DECLARE product_cursor CURSOR local SCROLL

NOT

DECLARE product_cursor SCROLL CURSOR

and Should have been:

decimal(8,2)

NOT

decimal.

Stupid mistakes! However, now I'm able to parse it fine, but am getting:

Msg 443, Level 16, State 15, Procedure CalculateFreight, Line 15

Invalid use of side-effecting or time-dependent operator in 'SELECT INTO' within a function.

Msg 443, Level 16, State 15, Procedure CalculateFreight, Line 25

Invalid use of side-effecting or time-dependent operator in 'UPDATE' within a function.

when I execute it!?

The SELECT INTO and UPDATE statements are fine when executed alone

Michelle