Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim myconnection As New SqlConnection
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"


Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Jun 22, 2015, 10:57 PM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Jun 23, 2015, 12:55 AM EDT
Saroj Kumar SahuRank #1,766 · 849 reputationPosted Jun 23, 2015, 3:31 AM EDT
King Umar106 reputationPosted Jun 23, 2015, 12:09 AM EDT
King Umar106 reputationPosted Jun 24, 2015, 7:09 PM EDT
Rafnas T PRank #280 · 8.8K reputationPosted Jan 10, 2017, 11:35 PM EST