Tengo este error al momento de intentar ejecutar la consulta:
'Fill: SelectCommand.Connection property has not been initialized.
Private Sub Verfactura_Load(sender As Object, e As EventArgs) Handles MyBase.Load
conectar()
filtrarfecha()
desconectar()
End Sub
Sub Filtarfecha()
Dim conexion As MySqlConnection = New MySqlConnection
Dim comando As MySqlCommand = New MySqlCommand
comando.CommandText = "SELECT p_fecha as Fecha, p_hora AS Hora, p_nfac as Factura, estatus AS Estatus,
SUM(p_monto) AS Total FROM tbl_Ventas
WHERE p_fecha = '" & fechac & "'
GROUP by p_fecha, p_nfac"
Dim dt As DataTable = New DataTable
Dim daa As MySqlDataAdapter = New MySqlDataAdapter(comando)
daa.Fill(dt)
DataGridViewX1.DataSource = dt
end sub
La conexión esta en un modulo:
Public cnn As New MySqlConnection
Public cmd As New MySqlCommand
Public ada As MySqlDataAdapter
Public Sub conectar()
Try
cnn.ConnectionString = "Server=localhost;Port=3306;Database=Venlite;Uid=root;Pwd=1234;"
cnn.Open()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub