PDA

View Full Version : ارسال sp به SQL از طریق ASP.NET



tc1000
پنج شنبه 06 دی 1386, 23:06 عصر
با سلام
لطفا دستورات ارسال SP ها به دیتا بیس SQL رو بگید
ممنون میشم
بطور مثال چند تا پارامتر رو ارسال کنید برای مثال
با تشکر

Sha2ow
پنج شنبه 06 دی 1386, 23:50 عصر
Public Shared Function InsertCustomnews(ByVal title As String, ByVal flddate As String, ByVal _
active As Boolean, ByVal picpath As String, ByVal categoryid As Integer, ByVal value As String, ByVal minitext As String) As Integer


Dim cmd As New SqlCommand("sp_add_customnews", GetConnection)

With cmd.Parameters
.AddWithValue("@fldtitle", title)
.AddWithValue("@flddate", flddate)
.AddWithValue("@fldactive", active)
.AddWithValue("@fldpicpath", picpath)
.AddWithValue("@fldcategoryid", categoryid)
.AddWithValue("@fldminitext", minitext)
.AddWithValue("@fldvalue", value)
End With

Return SqlExecuteInsertSpGetId(cmd)
End Function





Public Shared Function SqlExecuteInsertSpGetId(ByVal cmd As SqlCommand) As Integer
'================================================= ====================
'Execute an Insert Stored Procedure and return the Autonumber field
'================================================= ====================
Dim i As Integer
Dim par As New SqlParameter("@RETURN_VALUE", SqlDbType.Int)

cmd.CommandType = CommandType.StoredProcedure
par.Direction = ParameterDirection.ReturnValue
cmd.Parameters.Add(par)

Try

i = cmd.ExecuteNonQuery()

Catch ex As Exception
ErrorMessage = "ProDBObject.SqlExecuteInsertSpGetId(SqlCommand): " & ex.Message.ToString
Finally
cmd.Connection.Close()
End Try
Dim parVal As Integer = Convert.ToInt32(par.Value)
Return parVal

End Function