VB.Net调用存储过程

MSDN:

将存储过程用于命令

方法1: ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpguide/html/cpconusingstoredprocedureswithcommand.htm

Dim nwindConn As SqlConnection = New SqlConnection("Data Source=localhost;Integrated Security=SSPI;" & _

"Initial Catalog=northwind")

Dim salesCMD As SqlCommand = New SqlCommand("SalesByCategory", nwindConn)

salesCMD.CommandType = CommandType.StoredProcedure

Dim myParm As SqlParameter = salesCMD.Parameters.Add("@CategoryName", SqlDbType.NVarChar, 15)

myParm.Value = "Beverages"

nwindConn.Open()

Dim myReader As SqlDataReader = salesCMD.ExecuteReader()

Console.WriteLine("{0}, {1}", myReader.GetName(0), myReader.GetName(1))

Do While myReader.Read()

Console.WriteLine("{0}, ${1}", myReader.GetString(0), myReader.GetDecimal(1))

Loop

myReader.Close()

nwindConn.Close()

方法2

直接用用SQL语句执行的方法

SQL语句如下:

"exec 存储过程名 参数列"