Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is this really the code needed to get a value from SQL?
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01262166
Message ID:
01262185
Views:
20
Does the ExecuteScaler work on only select statements? I see what you are only returning one field, so what would happen if you need to fields?

>>That is a lot of work ... )-:
>>
>>
>
>Yep. It is less than having to play with a dataadapter, but still a pain.
>
>The ExecuteScalar (not execscalar as I wrote originally) at least gets the result fairly easily once the command is written.
>
>Here's a real example..
>
> Dim userID As String
> Dim cmd As New SqlCommand
> Dim conn As New SqlConnection
>
> conn.ConnectionString = ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString
>
> cmd.Connection = conn
>
> cmd.CommandText = "select userid from aspnet_users where username=@username"
> cmd.Parameters.Add("username", SqlDbType.VarChar)
> cmd.Parameters("username").Value = Me.CreateUserWizard1.UserName.ToString.Trim
>
> cmd.Connection.Open()
>
> userID = cmd.ExecuteScalar().ToString()
>
> cmd.Connection.Close()
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform