⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ordersdb.vb

📁 This is a book about vb.you could learn this from this book
💻 VB
字号:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections

Namespace IBuyAdventure

   Public Class OrdersDB

      Dim m_ConnectionString As String

      Public Sub New(dsn As String)
         m_ConnectionString = dsn
      End Sub
      
      Public Function GetOrdersForCustomer(customerName As String) As DataSet

          Dim sqlConnection As New SqlConnection(m_ConnectionString)
          Dim sqlAdapter1 As New SqlDataAdapter("SELECT * FROM Orders WHERE CustomerName='" _
          		& customerName & "'", sqlConnection)

          Dim products As New DataSet()
          sqlAdapter1.Fill(products, "products")

          Return products
          
      End Function
   
      Public Sub AddNewOrder(customerName As String, ordered As String, orderValue As Double)

          Dim insertStatement As String = "INSERT INTO Orders(CustomerName, Ordered, TotalValue)" _
          		& " values ('" & customerName & "', '" & ordered & "' , '" & orderValue & "')"

          Dim sqlConnection As New SqlConnection( m_ConnectionString)
          Dim myCommand As New SqlCommand(insertStatement, sqlConnection)

          myCommand.Connection.Open()
          myCommand.ExecuteNonQuery()
          myCommand.Connection.Close()
      
      End Sub

      Public Sub DeleteOrdersForCustomer(customerName As String)
      
          Dim updateStatement As String = "Delete Orders where customerName ='" & customerName & "'"

          Dim sqlConnection As New SqlConnection( m_ConnectionString)
          Dim myCommand As New SqlCommand(updateStatement, sqlConnection)

          myCommand.Connection.Open()
          myCommand.ExecuteNonQuery()
          myCommand.Connection.Close()

      End Sub

   End Class

End Namespace


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -