Newbie: Examples of ExecuteNonQuery

  • Thread starter Thread starter Parasyke
  • Start date Start date
P

Parasyke

Does anyone have any examples of "ExecuteNonQuery"? I've tried to grap
this phrase but examples may be my only way of understanding this
concept. Any real-world code snipits with a brief description would be
so kind.

Thanks!
 
You would use that for something that was going to execute but not
return anything (like an Update, Insert, or Delete statement)

Thanks,
Mick
 
I've cut out the error handling and input validation code so you can see the
idea clearly. Use when you do not need a return value (such as an Insert).

Public Sub AddNewCustomer()
Dim strSQLServer As New SqlConnection(strConn)

Dim cmd As New SqlCommand("CustomerInsert", strSQLServer)
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = strSQLServer

cmd.Parameters.Add(New SqlParameter("@Honorific", SqlDbType.VarChar, 10))
cmd.Parameters.Item(0).Value = txtSal.Text

cmd.Parameters.Add(New SqlParameter("@FirstName", SqlDbType.VarChar, 50))
cmd.Parameters.Item(1).Value = txtFirstName.Text

cmd.Parameters.Add(New SqlParameter("@LastName", SqlDbType.VarChar, 50))
cmd.Parameters.Item(2).Value = txtLastName.Text

strSQLServer.Open()
cmd.ExecuteNonQuery()

strSQLServer.Close()
End Sub
 
Back
Top