Tami Wohlers Tami Wohlers -3 years ago 148
Vb.net Question

"fill select command code has not been initialized" run time error on executable only

Dim myconn As New SqlConnection("Data Source = localhost\\SQLEXPRESS;
Initial Catalog = test2Forms; Integrated Security = SSPI;")
Dim myTable As New DataTable()
Dim myCmd As New SqlCommand()
myCmd.CommandText = "SELECT * FROM dbo.withActivityLog3 WHERE ID = @ID"
myCmd.Connection = myconn

Dim myAdapater As New SqlDataAdapter(myCmd)

DataGridView2.DataSource = myTable

This code works when I compile and test it on my primary computer, but when I upload it to the server and it is downloaded to test, it comes up with the above runtime error on the form load. I've looked at other related posts and it looks like it might be a matter of order of execution?

Answer Source

Do you not see an issue with this:

Dim myAdapater As New SqlDataAdapter(myCmd)

You set the CommandText of myAdapter and then call Fill on SqlDataAdapter1.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download