tbailey922
asked on
Reusing the SQLCommand in vb.net
I am using the sqlcommand often to execute queries on the SQL Server from my vb.net program. The problem I am having is that I have to keep retyping my commands. See below. Rather then redimming my commmands everytime is there a way to reuse them for ex. I want to reuse the cmd rather than renaming it to cmdprior. Also same applies to the irowsaffected variable.
Dim cmd As SqlCommand = New SqlCommand
Dim irowsaffected As Integer
cmd.CommandTimeout = "60"
cmd.CommandType = CommandType.Text
cmd.CommandText = "select count(*) from jcpmst1"
cmd.Connection = sqlupdate
sqlupdate.Open()
irowsaffected = cmd.ExecuteScalar
sqlupdate.Close()
cmd = Nothing
Dim cmdprior As SqlCommand = New SqlCommand
Dim irowsaffected3 As Integer
cmdprior.CommandTimeout = "90"
cmdprior.CommandText = "Delete from prior"
cmdprior.CommandType = CommandType.Text
cmdprior.Connection = sqlupdate
sqlupdate.Open()
irowsaffected3 = cmdprior.ExecuteNonQuery
sqlupdate.Close()
cmdprior = Nothing
irowsaffected3 = Nothing
Thanks
Tim
Dim cmd As SqlCommand = New SqlCommand
Dim irowsaffected As Integer
cmd.CommandTimeout = "60"
cmd.CommandType = CommandType.Text
cmd.CommandText = "select count(*) from jcpmst1"
cmd.Connection = sqlupdate
sqlupdate.Open()
irowsaffected = cmd.ExecuteScalar
sqlupdate.Close()
cmd = Nothing
Dim cmdprior As SqlCommand = New SqlCommand
Dim irowsaffected3 As Integer
cmdprior.CommandTimeout = "90"
cmdprior.CommandText = "Delete from prior"
cmdprior.CommandType = CommandType.Text
cmdprior.Connection = sqlupdate
sqlupdate.Open()
irowsaffected3 = cmdprior.ExecuteNonQuery
sqlupdate.Close()
cmdprior = Nothing
irowsaffected3 = Nothing
Thanks
Tim
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
Tim