Thursday, March 29, 2012

Get a value from SQL Database...

Sorry, this maybe a very easy problem...Embarrassed [:$] I just want to know how get a value from SQL database ... since I am new to SQL server...

I already have code like this:

Dim queryString As String = "SELECT Password FROM [User] WHERE Name = 'Sprite'"
Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

What should I do next to get the value ?Embarrassed [:$]

thx for your help

:)

Just had a try, and it works~ haha...Hmm [^o)]

Here is the code for other newbies...Smile [:)]

Dim connectionString As String = "Connection String Here"
Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)

Dim queryString As String = "Your SQL String Here"
Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbPassword as String
dbConnection.Open()
dbPassword = CType(dbCommand.ExecuteScalar, String)
dbConnection.Close()

Sorry for the trouble I made...Embarrassed [:$]

No comments:

Post a Comment