Hi I am trying to execute this vb.net code which is given below however it gives an invalid operation exception. I not very good in vb and am trying this for the first time. Please help me in resolving this issue.

Imports System.ExecutionEngineException
Imports System.InvalidOperationException

Imports System.Data.CommandBehavior
Imports System.Data
Imports System.Data.SqlTypes
Imports System.Data.Sql
Imports System.Data.SqlClient



Public Class txtemail


    Dim mySqlCommand As SqlCommand(sqlQry,mySqlConnection)
    Dim myDataReader As SqlDataReader
    Dim mySqlConnection As SqlConnection





    Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click


    End Sub

    Private Sub btnSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelect.Click
        mySqlConnection = New SqlConnection("server=OFFICE-D6830863\SQLEXPRESS1;Integrated Security = SSPI; database = CM")
        mySqlCommand = New SqlCommand("Select sno from cmtable,mysqlconnection")

        Try

            mySqlConnection.Open()
            myDataReader = mySqlCommand.ExecuteReader(CommandBehavior.CloseConnection)

            Do While (myDataReader.Read())
                txtsno.Text = myDataReader.GetString(0)
            Loop
        Catch ex As Exception
            MsgBox(ex.ToString())

        End Try

        myDataReader.Close()

        mySqlConnection.Close()
        



    End Sub
End Class

Edited 6 Years Ago by __avd: Added [code] tags.

This line:
mySqlCommand = New SqlCommand("Select sno from cmtable,mysqlconnection")
Move the quotation mark into this:
mySqlCommand = New SqlCommand("Select sno from cmtable", mySqlConnection)

This article has been dead for over six months. Start a new discussion instead.