Hello guys, I've question regarding retrieving of data from SQL
server 2005 and then displaying it on a textbox / label. So
hopefully I can find aid here. I've done some research and was
thinking of using dataReader to read and then display data. I'm
doing it 3-tier.
So these are my codes...
ViewInformationDAL.vb
Public Class ViewInformationDAL
Dim cmd As New
System.Data.SqlClient.SqlCommand
Sub New()
'Empty constructor
End Sub
Public Function viewInformation(ByVal username
As String, ByVal password As String) As String
Dim dReader As
System.Data.IDataReader = Nothing
Dim StrSelect As String
= "SELECT * FROM Members"
Dim msg As String =
Nothing
Try
retrieveDReader(StrSelect, dReader)
While dReader.Read
msg = "Successful"
End While
Catch ex As
System.Data.DataException
msg = ex.Message
End Try
Return msg
End Function
Public Sub retrieveDReader(ByVal StrSelect As
String, ByRef dReader As System.Data.IDataReader)
Dim connectionString As
String = My.Settings.dbConnection
Dim dbConnection As
System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(connectionString)
dbConnection.Open()
Try
cmd.Connection = dbConnection
cmd.CommandText = StrSelect
dReader = cmd.ExecuteReader
Catch ex As
Exception
End Try
End Sub
End Class
ViewInfoBLL.vb
Imports Microsoft.VisualBasic
Public Class ViewInfoBLL
Dim loginAdapter As DAL.LoginDAL = New
DAL.LoginDAL
Public Sub New()
End Sub
Public Function GetLogin(ByVal username As
String, ByVal password As String) As String
Dim str As String =
loginAdapter.GetLogin(username, password)
Return str
End Function
End Class
Default.aspx.vb
Partial Class Default
Inherits System.Web.UI.Page
Dim retrieveInfo As ViewInfoBLL = New
ViewInfoBLL
Protected Sub Page_Load(ByVal sender As Object,
ByVal e As System.EventArgs) Handles Me.Load
Dim username As String =
Nothing
Dim password As String =
Nothing
Dim Result As String =
retrieveInfo.GetLogin(username, password)
If Result = "Successful"
Then
'I want to display value thats from database into the question
marks part
TextBox1.Text = "???"
TextBox2.Text = "???"
Else
TextBox1.Text = "Error"
TextBox2.Text = "Error"
End If
End Sub
End Class
And lastly there's tableAdapter
Hopefully someone can enlighten me.Thanks alot and greatly
appreciated for any advices and helps.