 |
|
Web (ASP.NET) คำสั่งที่ใช้เขียนเพื่อเรียก Store Procedure มาใช้ต้องเขียนอย่างไรคะ เขียนเหมือนคำสั่ง SQL ไหมคะ??? |
|
 |
|
|
 |
 |
|
Syntax
CREATE PROC [ EDURE ] [ owner. ] procedure_name [ ; number ]
[ { @parameter data_type }
[ VARYING ] [ = default ] [ OUTPUT ]
] [ ,...n ]
[ WITH
{ RECOMPILE | ENCRYPTION | RECOMPILE , ENCRYPTION } ]
[ FOR REPLICATION ]
AS sql_statement [ ...n ]
http://msdn.microsoft.com/en-us/library/aa258259(v=sql.80).aspx
|
 |
 |
 |
 |
Date :
2011-12-06 10:06:23 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
การ Call Store Procedure
Code (VB.NET)
Private Sub btnGetAuthors_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnGetAuthors.Click
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyDataAdapter As SqlDataAdapter
'Create a connection to the SQL Server.
MyConnection = New SqlConnection("server=(local);database=pubs;Trusted_Connection=yes")
'Create a DataAdapter, and then provide the name of the stored procedure.
MyDataAdapter = New SqlDataAdapter("GetAuthorsByLastName", MyConnection)
'Set the command type as StoredProcedure.
MyDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure
'Create and add a parameter to Parameters collection for the stored procedure.
MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@au_lname", _
SqlDbType.VarChar, 40))
'Assign the search value to the parameter.
MyDataAdapter.SelectCommand.Parameters("@au_lname").Value = Trim(txtLastName.Text)
'Create and add an output parameter to Parameters collection.
MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@RowCount", _
SqlDbType.Int, 4))
'Set the direction for the parameter. This parameter returns the Rows returned.
MyDataAdapter.SelectCommand.Parameters("@RowCount").Direction = ParameterDirection.Output
DS = New DataSet() 'Create a new DataSet to hold the records.
MyDataAdapter.Fill(DS, "AuthorsByLastName") 'Fill the DataSet with the rows returned.
'Get the number of rows returned, and then assign it to the Label control.
'lblRowCount.Text = DS.Tables(0).Rows.Count().ToString() & " Rows Found!"
lblRowCount.Text = MyDataAdapter.SelectCommand.Parameters(1).Value & " Rows Found!"
'Set the data source for the DataGrid as the DataSet that holds the rows.
Grdauthors.DataSource = DS.Tables("AuthorsByLastName").DefaultView
'Bind the DataSet to the DataGrid.
'NOTE: If you do not call this method, the DataGrid is not displayed!
Grdauthors.DataBind()
MyDataAdapter.Dispose() 'Dispose of the DataAdapter.
MyConnection.Close() 'Close the connection.
End Sub
http://support.microsoft.com/kb/306574
|
 |
 |
 |
 |
Date :
2011-12-06 10:09:17 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แต่ถ้าผ่าน SQL Command สามารถเรียกผ่าน exec ได้เลยครับ
เช่น
Code (VB.NET)
Dim strSQL As String = " exec my_store_procedure 'p1','p2',... "
cmd.ExecuteNonQuery(strSQL)
|
 |
 |
 |
 |
Date :
2011-12-06 10:11:06 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|