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
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only