Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim myconnection As New SqlConnection
myconnection.ConnectionString = "Data Source=USER-PC;Initial Catalog=MiSInventory;Integrated Security=True"
Dim READER As SqlDataReader
Try
myconnection.Open()
Dim Query As String
Query = "SELECT COUNT(DISTINCT Category)AS NumCount FROM ItemAdd GROUP BY Category"
READER = Command.ExecuteReader
Command = New SqlCommand(Query, myconnection)
nDataAdapter = New SqlDataAdapter(Command)
ds = New DataSet()
nDataAdapter.Fill(ds)
TextBox1.Text = "ds.Tables[0].Rows[1][NumCount].ToString()"
MessageBox.Show("Data will be count")
myconnection.Close()
Catch ex As Exception
MessageBox.Show("Could not connect database: " & ex.Message, "Database Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
myconnection.Dispose()
End Try
End Sub
When i click the button count it says "object reference not set to an instance of an object"