Как я решаю эту ошибку "ССЫЛКА на объект не установлена на экземпляр объекта".
Imports System.Data.SqlClient Public Class Form2 Public myConn As SqlConnection Public myCmd As SqlCommand Public myReader As SqlDataReader Public results As String Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load 'Create a Connection object. myConn = New SqlConnection("Data Source=RADIANT-PC\SQLEXPRESS;Initial Catalog=crop;Integrated Security=True") End Sub 'To set up the Command object, which contains the SQL query, add the following code to the Form1_Load event procedure 'Create a Command object. Private Sub btnAddState_Click(sender As Object, e As EventArgs) Handles btnAddState.Click Try myCmd.CommandText = "INSERT INTO [dbo].[tblState] ([statename]) VALUES ('" & txtAddState.Text & "')" myCmd.Connection = myConn myConn.Open() myCmd.ExecuteNonQuery() MsgBox("Succesfully Added", MsgBoxStyle.Information, "add") myCmd.Dispose() Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub End Class
Что я уже пробовал:
'Try ' Get ' myCmd.CommandType = System.Data.CommandType.Text ' End Get ' Set(ByVal value As Integer) ' myCmd.CommandText = "" ' End Set 'Catch ex As Exception ' MessageBox.Show(ex.Message) 'End Try
Richard MacCutchan
Где происходит ошибка?