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:
01262173
Vues:
21
>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()
____________________________________

Don't Tread on Me

Overthrow the federal government NOW!
____________________________________
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform