Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Code: Private Sub btnSerach_Click(ByVal sender As System.Object, ByVal e As Syst

ID: 3548821 • Letter: C

Question

Code:

    Private Sub btnSerach_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSerach.Click

        Dim dt As DataTable
        Dim sqlstr As String

        sqlstr = "Select * from StudProfile where StudID = " & CInt(txtS.Text) & ""

        dt = New DataTable
        da = New OleDb.OleDbDataAdapter(sqlstr, con)
        da.Fill(dt)
        da.Dispose()

        If dt.Rows.Count = 0 Then

            MessageBox.Show("Not Found")

        Else

            txtID.Text = CStr(dt.Rows(0)(0))
            MessageBox.Show("Found")

        End If


Image database



Any error here?
please correct

Code: Private Sub btnSerach_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSerach.Click Dim dt As DataTable Dim sqlstr As String sqlstr = "Select * from StudProfile where StudID = " & CInt(txtS.Text) & "" dt = New DataTable da = New OleDb.OleDbDataAdapter(sqlstr, con) da.Fill(dt) da.Dispose() If dt.Rows.Count = 0 Then MessageBox.Show("Not Found") Else txtID.Text = CStr(dt.Rows(0)(0)) MessageBox.Show("Found") End If Image database Any error here? please correct

Explanation / Answer

Connection variable (con) not decalred in program.

And if StudID is integer data type then no need to use single quotes in sqlstr...

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote