473,400 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 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 2939
ilearneditonline
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)
  6.  
  7.         Dim idnumber As Integer = ???
  8.  
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

1
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 - for example in a OnClick-EventHandler of a...
5
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? Example: I have an SqlDataSource with a...
8
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 main tables. I read the value of the column in my...
3
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 MSSQL (like MySQL, Firebird or PostgreSQL) but I'm...
2
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 concurrency parameters - i.e. when I comment them...
0
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 following error: You have specified that your delete...
2
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 some of the record data back in the underlying...
2
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 Server 2000 db. Inside that db I have a table named...
1
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 :: ? On my first form i have used some...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.