Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Fill: SelectCommand.Connection property has not been initialized.
 

Fill: SelectCommand.Connection property has not been initialized.

please i need help
i wrote the below code and gave me an fill:selectCommand.connection property has not been initializded.
please help me urgent :(

cmd =

New OleDbCommand("select pid as [Patient ID], pname as [Patient Name], pgender as Gender, premarks as Remarks from patient_tb , con")

myda =

New OleDbDataAdapter(cmd)

mydataset =

New DataSet()

myda.Fill(mydataset,

"MyTable") (the error is in this line)

DataGridView1.DataSource = mydataset.Tables(

"MyTable")


Fill: SelectCommand.Connection property has not been initialized.
muhammadwow  Tuesday, August 25, 2009 10:26 PM
As From the code snippet , it is obvious that the connection string is not properly initialized. from the above OleDbCommand your passing the connection as a string with Query that is wrong.
there are two ways to initialize connection string pass the oledbConnection or connection string in OleDbCommand with two constructor parameters one is Query and the other is connection.
If you don't pass the connection in oleDbCommand the pass the Connection in OleDbAdapter with OleDbCommand in Adapter Connection i thing it working fine.
before executing the command first check the connection state is opened successfully , executed command and close the connection..

thanks.

Malik M.Shahid  Wednesday, August 26, 2009 12:30 AM
As From the code snippet , it is obvious that the connection string is not properly initialized. from the above OleDbCommand your passing the connection as a string with Query that is wrong.
there are two ways to initialize connection string pass the oledbConnection or connection string in OleDbCommand with two constructor parameters one is Query and the other is connection.
If you don't pass the connection in oleDbCommand the pass the Connection in OleDbAdapter with OleDbCommand in Adapter Connection i thing it working fine.
before executing the command first check the connection state is opened successfully , executed command and close the connection..

thanks.

Malik M.Shahid  Wednesday, August 26, 2009 12:30 AM

You can use google to search for other answers

Custom Search

More Threads

• How to lock a control on a design form
• Showing context menus with the DesignSurface class.
• Need tips on creating a professional looking program.
• My Data Binding Solution for a "Browse for Drive" Dialog Box
• Alpha-Blending a Control at Design Time
• how to validate masktextbox
• Winforms controls get dislocated
• Problem with Form Display
• Clone Copy a Panel with its controls
• How to load a form by myself ?