Please tell what's wrong in this code.. I am using 3 DateTimePicker.. I think that line has some problem...Please Help..

Untitled.jpg

Recommended Answers

All 5 Replies

I'd have to guess that cmdSearch is not defined. I suggest putting a breakpoint on that line then adding a watch on cmdSearch to see what's up. Please post the code where cmdSearch is defined and identify its scope. It is possible that you declared it without the New keyword which would give you a reference variable rather than an object instance.

commented: Yes sir, I am posting the code where i declared cmdSearch . +0
 Imports System.Data.OleDb
 Imports System.Data

Public Class Form9
Dim cnnOLEDB As New OleDbConnection

Dim cmdUpdate As OleDbCommand
Dim cmdSearch As OleDbCommand
Dim cmdDelete As OleDbCommand

Dim strConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=.\\DatabaseCSMS.accdb"

 Private Sub Form9_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    cnnOLEDB.ConnectionString = strConnectionString
    cnnOLEDB.Open()
End Sub
 Private Sub btnsea3_Click(sender As Object, e As EventArgs) Handles btnsea3.Click
    Dim vSearch As String = InputBox("Enter Employee Id to search the details:")
    If vSearch <> "" Then
        cmdSearch.CommandText = "SELECT * from Employee_Details WHERE Emp_Id = " & CInt(vSearch)
        cmdSearch.Connection = cnnOLEDB
        Dim rdrOLEDB As OleDbDataReader = cmdSearch.ExecuteReader
        If rdrOLEDB.Read = True Then
            cbeid1.Text = rdrOLEDB.Item(0).ToString
            txtepn2.Text = rdrOLEDB.Item(1).ToString
            txtadd3.Text = rdrOLEDB.Item(2).ToString
            txtphon4.Text = rdrOLEDB.Item(3).ToString
            dtpdobi5.Value = rdrOLEDB.Item(4).ToString
            txtapt6.Text = rdrOLEDB.Item(5).ToString
            dtpdte7.Value = rdrOLEDB.Item(6).ToString
            dtpdoa8.Value = rdrOLEDB.Item(7).ToString
            rdrOLEDB.Close()
            MsgBox("Record found")
            Exit Sub
        Else
            rdrOLEDB.Close()
            MsgBox("Record not found")
            Exit Sub
        End If
    Else
        MsgBox("Enter search value.")
        Exit Sub
    End If

End Sub

You see where you did

Dim cmdUpdate As OleDbCommand
Dim cmdSearch As OleDbCommand
Dim cmdDelete As OleDbCommand

What you have done is define pointers to specific objects but you didn't actually create those objects. What you want is

Dim cmdUpdate As New OleDbCommand
Dim cmdSearch As New OleDbCommand
Dim cmdDelete As New OleDbCommand

This creates the objects.

commented: Thank You so much sir..my error is solved.. +0

Thank You :-)

Glad I could help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.