Newbie: Declaring Variables

S

Steven K

Hello,

I am trying to convert an ASP application to ASP .Net. The first issue I
have come across is declaring the variables for my connection to SQL Sever
2K stored procedures:

Dim strParm00 As String
Dim spSearch
Dim con_search
Dim adcmdStoredProc

Set spSearch = con_search.Execute("sp_web_Search " & strParm00,
adcmdStoredProc)

I would appreciate any help with declaring these variables. Also, are there
any resources on the web that can help with this?
 
A

Alvin Bruney [MVP]

The easiest way to convert a project is to change the extension to aspx from
asp. Run it see if anything breaks. Most likely it doesn't and you don't
have to do anything. Otherwise you just fix the disturbed lines. Are you up
to this point?
 
S

Scott M.

You need to declare an ADO.NET Command object and set its commandType
property to Stored Procedure, then you can set the commandText property to
your stored procedure name. You may need to declare parameter objects as
well depending on if you have any. When you execute your command, it will
do what it needs to.

I would suggest an MSDN search on ".NET Command"
 
R

Raterus

I'd start here
http://www.ondotnet.com/pub/a/dotnet/2002/09/22/vb-oop.html

This won't answer your question one bit, but hopefully it will get you on
the right track for how to structure your programs.

I'm going to answer your question, but it'll help to know the concepts in
that article first, because not only will you have to declare the variables,
you'l have to instantiate them before you can use them.

In the end it'll look something like this, I added some error handling too

Imports System.Data.SqlClient

Class MyClass
Private conn as SqlConnection 'I could have put conn as
System.Data.SqlClient.SqlConnection, but since I have the imports statement,
I can simplify it
Public Sub mySub()
Dim strParam as String = "blahblah", Search as string
conn = new SqlConnection("your connection string")
Dim cmd as SqlCommand = new SqlCommand("your stored procedurename",
conn)
cmd.paramters.add(@myParam, strParm00)

try
conn.open
Search = cstr(cmd.executeScalar())
catch ex as exception
response.write "Error: " & ex.tostring()
finally
conn.close
end try

End Sub
End Class

Hope this helps,
--Michael
 
S

Scott M.

It may be the "easiest" way, but hardly the "best" way since you could
easily wind up with legacy code that is not as efficient as .NET code. It
also doesn't address the many differences between VBScript and VB.NET as
well as the codebehind paradigm.

Alvin Bruney said:
The easiest way to convert a project is to change the extension to aspx from
asp. Run it see if anything breaks. Most likely it doesn't and you don't
have to do anything. Otherwise you just fix the disturbed lines. Are you up
to this point?

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Steven K said:
Hello,

I am trying to convert an ASP application to ASP .Net. The first issue I
have come across is declaring the variables for my connection to SQL Sever
2K stored procedures:

Dim strParm00 As String
Dim spSearch
Dim con_search
Dim adcmdStoredProc

Set spSearch = con_search.Execute("sp_web_Search " & strParm00,
adcmdStoredProc)

I would appreciate any help with declaring these variables. Also, are there
any resources on the web that can help with this?
 
A

Alvin Bruney [MVP]

Agreed.

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Scott M. said:
It may be the "easiest" way, but hardly the "best" way since you could
easily wind up with legacy code that is not as efficient as .NET code. It
also doesn't address the many differences between VBScript and VB.NET as
well as the codebehind paradigm.

Alvin Bruney said:
The easiest way to convert a project is to change the extension to aspx from
asp. Run it see if anything breaks. Most likely it doesn't and you don't
have to do anything. Otherwise you just fix the disturbed lines. Are you up
to this point?

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Steven K said:
Hello,

I am trying to convert an ASP application to ASP .Net. The first
issue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top