Ø
Øyvind Isaksen
In asp 3.0 I used an procedure (that I included) to save and update
articles, like this:
<%
Sub ConnObj(SQL)
set cn = server.CreateObject("ADODB.Connection")
cn.Open ConnString
cn.Execute SQL
cn.Close
Set cn = nothing
End Sub
'Just call the procedure with SQL an input:
call ConnObj(SQL)
%>
I would like to to the same thing i ASP.NET, but dont know the right way to
do it. I wonder what to do with the "parameters", since the SQL needs to be
an input?
In this procedure, I would write "Dim SQL as string = inputSQL". But I dont
know what to do with the parameters? Is there a smart way to make a
procedure that I can use to execute a SQL, or do I need to write the entire
code each time?
PS: I need a procedure I can use for different SQL's (and databasefields)...
if it is possible without making a new "spesific" procedure based on what I
need to save?
------------------------
Example:
-----------------------
Private Sub SaveArticle(inputSQL)
Dim conn As New SqlConnection(variables.ConnString)
Dim SQL as string = "insert into tblEmployee (fname,lname) values
(@fname,@lname)"
Dim cmd As New SqlCommand(SQL, conn)
Dim parameter1 As New SqlParameter("@fname", Me.txtFname.Text)
cmd.Parameters.Add(parameter1)
Dim parameter2 As New SqlParameter("@lname", Me.txtLname.Text)
cmd.Parameters.Add(parameter2)
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
cmd.Dispose()
conn.Dispose()
End Sub
articles, like this:
<%
Sub ConnObj(SQL)
set cn = server.CreateObject("ADODB.Connection")
cn.Open ConnString
cn.Execute SQL
cn.Close
Set cn = nothing
End Sub
'Just call the procedure with SQL an input:
call ConnObj(SQL)
%>
I would like to to the same thing i ASP.NET, but dont know the right way to
do it. I wonder what to do with the "parameters", since the SQL needs to be
an input?
In this procedure, I would write "Dim SQL as string = inputSQL". But I dont
know what to do with the parameters? Is there a smart way to make a
procedure that I can use to execute a SQL, or do I need to write the entire
code each time?
PS: I need a procedure I can use for different SQL's (and databasefields)...
if it is possible without making a new "spesific" procedure based on what I
need to save?
------------------------
Example:
-----------------------
Private Sub SaveArticle(inputSQL)
Dim conn As New SqlConnection(variables.ConnString)
Dim SQL as string = "insert into tblEmployee (fname,lname) values
(@fname,@lname)"
Dim cmd As New SqlCommand(SQL, conn)
Dim parameter1 As New SqlParameter("@fname", Me.txtFname.Text)
cmd.Parameters.Add(parameter1)
Dim parameter2 As New SqlParameter("@lname", Me.txtLname.Text)
cmd.Parameters.Add(parameter2)
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
cmd.Dispose()
conn.Dispose()
End Sub