VB.NET SQL Server Insert - ExecuteNonQuery: Connection property has not been initialized

前端 未结 5 644
醉话见心
醉话见心 2021-01-20 01:17

In the form load event, I connect to the SQL Server database:

Private Sub AddBook_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles My         


        
5条回答
  •  旧时难觅i
    2021-01-20 01:50

    Module Module1 Public con As System.Data.SqlClient.SqlConnection Public com As System.Data.SqlClient.SqlCommand Public ds As System.Data.SqlClient.SqlDataReader Dim sqlstr As String

    Public Sub main()
        con = New SqlConnection("Data Source=.....;Initial Catalog=.....;Integrated Security=True;")
        con.Open()
        frmopen.Show()
        'sqlstr = "select * from name1"
        'com = New SqlCommand(sqlstr, con)
        Try
            com.ExecuteNonQuery()
    
            'MsgBox("success", MsgBoxStyle.Information)
        Catch ex As Exception
            MsgBox(ex.Message())
        End Try
        'con.Close()
    
    
    
        'MsgBox("ok", MsgBoxStyle.Information, )
    
    End Sub
    

    End Module

提交回复
热议问题