offline exam software
frnds mala offline exam software banvayache aahe tar plz hlp kara
Imports MySql.Data.MySqlClient Public Class Form1 'create a public function and set your MySQL Connection . Public Function mysqlconnection() As MySqlConnection 'return new connection. Return New MySqlConnection("server=localhost;user id=root;database=userdb") End Function 'put the value of mysqlconnection() as MySQL connection to con. Public con As MySqlConnection = mysqlconnection() End Class
'declaring the classes 'a set of command in MySQL Dim cmd As New MySqlCommand 'represent a new spicific table in the database Public dt As New DataTable 'serve as the bridge of mysql database and the datatable for saving and retrieving data. Public da As New MySqlDataAdapter
'create a sub procedure named "create" and the parameter's type is string Public Sub create(ByVal sql As String) Try 'open the connection con.Open() 'set your command With cmd 'holds the data to be executed .Connection = con .CommandText = sql 'execute the data result = cmd.ExecuteNonQuery 'coditioning the result whether succesfull or failed when it is executed. If result = 0 Then 'the execution of data is failed Else 'the executed data is succesfull End If End With Catch ex As Exception End Try End Sub
'create a sub procedure named "loginUser" and the parameter's type is string Public Sub loginUser(ByVal sql As String) Try 'declaring the variable as integer Dim maxrow As Integer 'open the connection con.Open() 'it will set a new specific table in the database dt = New DataTable 'set a command With cmd 'holds the data .Connection = con .CommandText = sql End With 'retriving the data da.SelectCommand = cmd da.Fill(dt) 'put the max value of rows in the table to a variable(maxrow) maxrow = dt.Rows.Count 'conditioning the total value of rows in the table 'if the total value of rows in the table is greater than 0 then the result is true ' and if not, the result is false If maxrow > 0 Then 'appearing the record of the current row and the current column in the current table. Else 'the result is false End If Catch ex As Exception End Try da.Dispose() End Sub
Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click 'put the string value to sql sql = "INSERT INTO `users` (`name`, `username`, `Pass`, `type` ) VALUES ('" _ & txtname.Text & "','" & txtuser.Text & "','" & txtpass.Text & "','" & cbotype.Text & "')" 'call your sub name and put the sql in the parameters list. create(sql) End Sub
Private Sub btnlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click 'put the string value to sql sql = "SELECT * from users WHERE username = '" & username.Text & "' and Pass = '" & password.Text & "'" 'call your sub name and put the sql in the parameters list. loginUser(sql) End Sub