Friday, February 24, 2012

how to retriece single record in database by using SqlDataSource??

Is me again,and now i facing problem to retrieve a single record from the database.

here is my code:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim user As String
user = TextBox1.Text
Dim varpassword
Dim mydata As SqlDataSource

mydata.SelectCommand = "Select * from tbluser where uLogin = '" & user & "'"
varpassword = mydata.SelectCommand.uPassword

End Sub
End Class

but i get the error : 'uPassword' is not a member of 'String'

i wan to retrieve the password of that user,can anyone help me?

thanksSmile

First create a select parameter "uPassword" of type "String".

|||

Girijesh:

First create a select parameter "uPassword" of type "String".

i not really understand about creating the select parameter.

can u write the line of code for me?thanksSmile

|||

Hi there,

Use this:

imports System.Data.Sql

Dim dt as new DataTable

Dim query As String = "Select * from tbluser where uLogin = '" & user & "'"

Dim conn as new SqlConnection(connection)

Dim adapter as new SqlDataAdapter

adapter.SelectCommand =new SqlCommand(query, conn);
adapter.Fill(dt);

// this DataTable only has one row, the one for this username

Dim password As String = dt.rows(0)("uPassword")

hope it helps you out,

gonzzas

No comments:

Post a Comment