Logo 
Search:

Asp.net Answers

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds
  Question Asked By: Meenachi Suppiah   on Aug 20 In Asp.net Category.

  
Question Answered By: Lewis Welch   on Aug 20

According to the docs, ExecuteNonQuery only returns  a value other
than -1 on UPDATE, INSERT and DELETE statements. However, your kind
reply stimulated my problem-solving brain cell (I only have one left)
when you wrote " ... returns an integer of records affected."

I "discovered", then used the DataReader.RecordsAffected property.
I'm using the Microsoft.Data.Odbc classes for this exercise, so:


Dim myExecuteQuery as String = "CREATE database  IF NOT exists  my_database"
myConnection.Open()
Dim myCommand As New OdbcCommand(myExecuteQuery, myConnection)

'Need to use a DataReader before accessing the RecordsAffected property

Dim myDataResults as OdbcDataReader
myDataResults = myCommand.ExecuteReader()
myDataResults.Read()
myDataResults.Close()

'After the DataReader is closed, the RecordsAffected property is set.

DbMessage.Text = myDataResults.RecordsAffected()
If DbMessage.Text = "0"
formMessage.Text = "Database already exists."
Else If DbMessage.Text = "1"
formMessage.Text = "Database created."
End If

MyConnection.Close()

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Database Messages Or get search suggestion and latest updates.


Tagged: