I have a SqlDataSource - The select statementselects the DB row with an ID that equals a querystring value... So Iknow I am only selecting one row..
Now I want to create a littleSub that grabs any field(s) of my choice and then I can assign thevalue of it to a textbox on my page or a variable if I need to... Anyidea how I actually reference the fields via the SQLDataSource in asub?
I see you can reference parameters using..
SqlDataSource1.SelectParameters()
I was hoping I could use something similar to get the actual DB fields like the below...
SqlDataSource1.Select("MyDataBaseField").Value = TextBox.Text
Can anyone help please??
Thanks
Hmmm I feared that... As I didn't want to use a gridview of details veiw etc...
I'll have a re-think... Thanks
I wrote a blog post about doing what I think you need:
http://peterkellner.net/2006/10/27/smalllistaccessimproved/
just use sqldatasource instead of objectdatasource and the same technique should work.
|||Thanks Peter... I think I was trying to do something that just wasnt possible... I have had a re-think... Thanks for the link though|||If you don't want to use the data controls, then don't use the sqldatasource.
In your sub, just do your own sqlconnection and command and get your data and assign the values to your controls...
Dim conn as new sqlconnection(ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectString)
dim cmd as new sqlcommand("SELECT field1,field2 FROM MyTable WHEREID=@.ID",conn)
cmd.parameters.add("@.ID",sqldbtype.integer).value=request.querystring("ID")
dim dr as datareader
conn.open
dr=cmd.executereader
dr.read
textbox1.text=dr("field1")
textbox2.text=dr("field2")
dr.close
conn.close
|||
Hi Motley,,,, Thanks for the advice ... I had actually gone down that route on Friday, but had the problem below??
http://forums.asp.net/thread/1468801.aspx
Any ideas? Seems to work fine if I don't use the connection string from my web.config... Even though I use the connection for loads of other pages (SQLDataSources) and its fine? Any ideas? Its driving me nuts
No comments:
Post a Comment