Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Is this really the code needed to get a value from SQL?
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01262166
Message ID:
01262185
Vues:
21
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()
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform