monkeynote
Member
- Joined
- Nov 17, 2007
- Messages
- 10
hello guys!
i would like to share my problem with regards to converting my classic vb code to vb.net and one of this is my Query Function.
i have this code that passes SQLStatement and returns the recordset as datareader but im having an error in reader variable and it tells me that reader has no constructors! what does this error mean? what is a constructor? how can i prevent my code from having this error?
This is the code from frmUsers.vb file
This is my Querystring Function in my SQL.vb class
ive been working on this all day and sad to say, i cant find any solution for this problem. i hope that you can help me with regards to my problem
i would like to share my problem with regards to converting my classic vb code to vb.net and one of this is my Query Function.
i have this code that passes SQLStatement and returns the recordset as datareader but im having an error in reader variable and it tells me that reader has no constructors! what does this error mean? what is a constructor? how can i prevent my code from having this error?
This is the code from frmUsers.vb file
Code:
Imports System.Data.SqlClient
Public Class frmUsers
Private Sub frmUsers_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim reader As New SqlDataReader
Dim sqlStatement As String, err As String
sqlStatement = "SELECT username, password, fullname, accesslevel FROM users"
reader = obj.Query(sqlStatement, err)
If reader.HasRows Then
DataGrid.DataSource = reader
End If
End Sub
End Class
This is my Querystring Function in my SQL.vb class
Code:
Public Function Query(ByVal sqlStatement As String) As SqlDataReader
Try
Dim cm As New SqlCommand
cm.Connection = cn Set a Connection
cm.CommandText = sqlStatement Execute SQL Statement
cm.CommandType = CommandType.TableDirect Refers that the command is SQL and not Stored Proc
Query = cm.ExecuteReader(CommandBehavior.CloseConnection)
Catch ex As Exception
Query = Nothing
End Try
End Function
ive been working on this all day and sad to say, i cant find any solution for this problem. i hope that you can help me with regards to my problem