472,341 Members | 1,910 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,341 software developers and data experts.

Converting SqlDataSource to String.

I was wondering how to convert an SqlDataSource to a string if you're sure the select statement will return only one element.
Aug 1 '07 #1
4 2875
130 Expert 100+
I was wondering how to convert an SqlDataSource to a string if you're sure the select statement will return only one element.
Not sure what you are looking for, but maybe this helps.

Expand|Select|Wrap|Line Numbers
  1. public function getNodeName(ByVal nodeid As Integer) As String
  2.     Dim query As String = "SELECT node_name FROM t_nodes WHERE node_id=" & nodeid
  3.     Using conn As New SqlConnection(Me.ConnectionString)
  4.         Dim cmd As New SqlCommand(query, conn)
  5.         conn.Open()
  6.         return Convert.ToString(cmd.ExecuteScalar())
  7.     End Using
  8. end function
Aug 2 '07 #2
What I need might be explained a bit better by this. Help would be greatly appreciated.

Expand|Select|Wrap|Line Numbers
  1.         Dim getid As New SqlDataSource
  2.         getid.ConnectionString = ConfigurationManager.ConnectionStrings("MegaMeepConnectionString1").ToString()
  3.         getid.InsertCommandType = SqlDataSourceCommandType.Text
  4.         getid.InsertCommand = "SELECT UserID FROM Profile WHERE UserName = @name"
  5.         getid.InsertParameters.Add("name", Login1.UserName)
  7.         Dim idnumber As Integer = ???
I need idnumber to equal the what the getid datasource selected. Is it easy to do?
Aug 2 '07 #3
Try an Output parameter and return ID in SQL
Aug 2 '07 #4
I take back my post, Are you inserting a new User with the given name or just trying to return the ID of an already existing User. If the latter I believe the code posted previously execute.scalar is what you need.
Aug 2 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

by: fuchs.markus | last post by:
Hello, on my page, I have a DetailsViewControl connected to a SqlDataSource. Now when I dynamically set the FilterExpression and FilterParameters -...
by: Martin Bischoff | last post by:
Hi, is it possible to modify the values of a SqlDataSource's select parameters in the code behind before the select command is executed? ...
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my...
by: zapov | last post by:
Hi! Did anyone successfully managed to use some custom ADO.NET provider with SqlDataSource? I'd like to connect to some other database than...
by: stuart.d.jones | last post by:
Hi, I'm using a detailsview control with an SqlDataSource control. My Update query isn't working, and I've narrowed it down to the optimistic...
by: Ed | last post by:
All of a sudden my previously working code started throwing this error. from the SqlDatasource. I am using C# and Asp.net 2.0. Getting the...
by: phil | last post by:
I have an ASP.NET application with an SQLdataSource and a Gridview Everything works very well except I have a 'Button' that goes off and changes...
by: Brad Isaacs | last post by:
Good evening friends, I have added a Drop Down List box control to my web form. I am using the web.config connection string to access my SQL...
by: sheenaa | last post by:
Hello Members, I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005. What i have used on forms ::...
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.