2006-11-13
Asp.Net2.0 自訂元件
一個簡單的class
Public Class MyFunction
Shared Function add(ByVal x As Integer, ByVal y As Integer)
Return x + y
End Function
End Class
可新增一個NameSpace
範例寫一個insert
Sub InsertTitle(ByVal title_id As String, ByVal title As String, ByVal type As String, ByVal price As Decimal)
Dim cn As New SqlConnection("Server=localhost;Database=Pubs;UID=sa;PWD=;")
Dim cmd As New SqlCommand("insert into titles (title_id,title,type,price) values (@title_id,@title,@type,@price)", cn)
cmd.Parameters.AddWithValue("@title_id", title_id)
cmd.Parameters.AddWithValue("@title", title)
cmd.Parameters.AddWithValue("@type", type)
cmd.Parameters.AddWithValue("@price", price)
cn.Open()
cmd.ExecuteNonQuery()
cn.Close()
End Sub
Public Class MyFunction
Shared Function add(ByVal x As Integer, ByVal y As Integer)
Return x + y
End Function
End Class
可新增一個NameSpace
範例寫一個insert
Sub InsertTitle(ByVal title_id As String, ByVal title As String, ByVal type As String, ByVal price As Decimal)
Dim cn As New SqlConnection("Server=localhost;Database=Pubs;UID=sa;PWD=;")
Dim cmd As New SqlCommand("insert into titles (title_id,title,type,price) values (@title_id,@title,@type,@price)", cn)
cmd.Parameters.AddWithValue("@title_id", title_id)
cmd.Parameters.AddWithValue("@title", title)
cmd.Parameters.AddWithValue("@type", type)
cmd.Parameters.AddWithValue("@price", price)
cn.Open()
cmd.ExecuteNonQuery()
cn.Close()
End Sub