in stuednt admin i wan it to insert and also select from tbl_stuendadmin how to put it togeter

    If String.IsNullOrWhiteSpace(txtcard.Text) Or String.IsNullOrWhiteSpace(txtadmno.Text) Then
        MessageBox.Show("Please complete the on the box.", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Exit Sub
    End If

    Dim Conn As System.Data.OleDb.OleDbConnection
    Dim ConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\temp\Database1.accdb"
    Conn = New System.Data.OleDb.OleDbConnection(ConnectionString)


    Try
        If Conn.State = ConnectionState.Open Then Conn.Close()
        Conn.Open()

        Dim sql As String = "insert into tbl_datain ([Stud Admin], [Admin Card]) values('" & txtadmno.Text & "', '" & txtcard.Text & "')"
        Dim sqlCom As New System.Data.OleDb.OleDbCommand(sql, Conn)
        sqlCom.Connection = Conn

        Dim result As Integer = sqlCom.ExecuteNonQuery()

        sqlCom.Dispose()
        Conn.Close()

        If result > 0 Then
            MessageBox.Show("Successfully Register.")
        Else
            MessageBox.Show("Failure to create.")

        End If
        txtadmno.Text = ""
        txtcard.Text = ""
        txtadmno.Focus()

        Lecturer_Form.Show()
    Catch ex As Exception
        MessageBox.Show("Failed to connect to Database..", "Database Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try

End Sub

You can create a command object with multiple SQL Statement. Like

Dim CMD As New System.Data.OleDb.OleDbCommand

CMD.CommandText = "Select * From Table1; Select * From Table2"

And you can work with every select statement one by one.

This article has been dead for over six months. Start a new discussion instead.