I want to change this parameterized query
On Error Resume Next
Dim timex As String
Dim isigroup As DataTable
objdata = New clsMSSQL
isigroup = objdata.QueryDatabase("SELECT * FROM Userx WHERE Username='" & txtuser.Text & "' AND Userpass ='" & txtpassword.Text & "'")
If isigroup.Rows.Count > 0 Then
For i = 0 To isigroup.Rows.Count - 1
If isigroup.Rows(i)("username") <> txtuser.Text Or isigroup.Rows(i)("userpass") <> txtpassword.Text Then
MsgBox("Access denied username and password !!!", MsgBoxStyle.Information, "Attention.....")
xcountx = xcountx + 1
If xcountx >= 3 Then
MsgBox("You have reach the maximum time of login !!", MsgBoxStyle.Exclamation, "Προσοχή.....")
End
End If
Exit Sub
End If
Next
username = isigroup.Rows(0)("Username")
xUser_ID = isigroup.Rows(0)("User_id")
xUser_Access = isigroup.Rows(0)("Access_Type")
timex = TimeOfDay
isigroup = objdata.QueryDatabase("INSERT INTO Audit_Log (User_ID, Login) VALUES(" & xUser_ID & ", '" & timex & "')")
isigroup = objdata.QueryDatabase("SELECT * FROM Audit_Log ORDER BY LOG_ID DESC")
LOGID = isigroup.Rows(0)("LOG_ID")
Audit_Trail(xUser_ID, TimeOfDay, "Login to system ")
I tried a lot but i can't make it please help
This is the class
Imports System.Data.SqlClient
Public Class clsMSSQL
Public Shared con As New SqlConnection(constring)
Private DbSwtable As DataTable
Public Function QueryDatabase(ByVal Query As String) As DataTable
Try
Dim objDataSet As New DataSet
Dim objDataTable As New DataTable
Dim objDataAdapter As New SqlDataAdapter(Query, con)
objDataAdapter.Fill(objDataSet, "DefaultTable")
objDataTable = objDataSet.Tables("DefaultTable")
con.Close()
Return objDataTable
Catch ex As Exception
MessageBox.Show(ex.Message, "Λάθος", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return DbSwtable
End Try
End Function
On Error Resume Next- use Try Catch blocks. You need to post the code forQueryDatabase, as that is where your query appears to be executed and where you will do the parameterization.