form1.vb

来自「Mastering VBNet Include Source Code」· VB 代码 · 共 417 行 · 第 1/3 页

VB
417
字号
        "tName, @SupplierID, @CategoryID, @QuantityPerUnit, @UnitPrice, @UnitsInStock, @U" & _
        "nitsOnOrder, @ReorderLevel, @Discontinued); SELECT ProductID, ProductName, Suppl" & _
        "ierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, Reord" & _
        "erLevel, Discontinued FROM dbo.Products WHERE (ProductID = @@IDENTITY)"
        Me.SqlInsertCommand1.Connection = Me.SqlConnection1
        Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@ProductName", System.Data.SqlDbType.NVarChar, 40, "ProductName"))
        Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@SupplierID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, True, CType(0, Byte), CType(0, Byte), "SupplierID", System.Data.DataRowVersion.Current, Nothing))
        Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@CategoryID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, True, CType(0, Byte), CType(0, Byte), "CategoryID", System.Data.DataRowVersion.Current, Nothing))
        Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@QuantityPerUnit", System.Data.SqlDbType.NVarChar, 20, System.Data.ParameterDirection.Input, True, CType(0, Byte), CType(0, Byte), "QuantityPerUnit", System.Data.DataRowVersion.Current, Nothing))
        Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@UnitPrice", System.Data.SqlDbType.Money, 8, System.Data.ParameterDirection.Input, True, CType(0, Byte), CType(0, Byte), "UnitPrice", System.Data.DataRowVersion.Current, Nothing))
        Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@UnitsInStock", System.Data.SqlDbType.Int, 2, System.Data.ParameterDirection.Input, True, CType(0, Byte), CType(0, Byte), "UnitsInStock", System.Data.DataRowVersion.Current, Nothing))
        Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@UnitsOnOrder", System.Data.SqlDbType.Int, 2, System.Data.ParameterDirection.Input, True, CType(0, Byte), CType(0, Byte), "UnitsOnOrder", System.Data.DataRowVersion.Current, Nothing))
        Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@ReorderLevel", System.Data.SqlDbType.Int, 2, System.Data.ParameterDirection.Input, True, CType(0, Byte), CType(0, Byte), "ReorderLevel", System.Data.DataRowVersion.Current, Nothing))
        Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Discontinued", System.Data.SqlDbType.Bit, 1, "Discontinued"))
        '
        'TextBox1
        '
        Me.TextBox1.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.DsProducts1, "Products.ProductName"))
        Me.TextBox1.Font = New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TextBox1.Location = New System.Drawing.Point(296, 16)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(264, 22)
        Me.TextBox1.TabIndex = 0
        Me.TextBox1.Text = ""
        '
        'DASuppliers
        '
        Me.DASuppliers.SelectCommand = Me.SqlSelectCommand2
        Me.DASuppliers.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "Suppliers", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("SupplierID", "SupplierID"), New System.Data.Common.DataColumnMapping("CompanyName", "CompanyName")})})
        '
        'SqlSelectCommand2
        '
        Me.SqlSelectCommand2.CommandText = "SELECT SupplierID, CompanyName FROM dbo.Suppliers"
        Me.SqlSelectCommand2.Connection = Me.SqlConnection1
        '
        'Button2
        '
        Me.Button2.Font = New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Button2.Location = New System.Drawing.Point(424, 206)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(136, 32)
        Me.Button2.TabIndex = 5
        Me.Button2.Text = "Update Database"
        '
        'ComboBox2
        '
        Me.ComboBox2.DataBindings.Add(New System.Windows.Forms.Binding("SelectedValue", Me.DsProducts1, "Products.SupplierID"))
        Me.ComboBox2.DataSource = Me.DsProducts1.Suppliers
        Me.ComboBox2.DisplayMember = "CompanyName"
        Me.ComboBox2.DropDownWidth = 176
        Me.ComboBox2.Font = New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ComboBox2.Location = New System.Drawing.Point(296, 152)
        Me.ComboBox2.Name = "ComboBox2"
        Me.ComboBox2.Size = New System.Drawing.Size(240, 22)
        Me.ComboBox2.TabIndex = 4
        Me.ComboBox2.Text = "ComboBox2"
        Me.ComboBox2.ValueMember = "SupplierID"
        '
        'ComboBox1
        '
        Me.ComboBox1.DataBindings.Add(New System.Windows.Forms.Binding("SelectedValue", Me.DsProducts1, "Products.CategoryID"))
        Me.ComboBox1.DataSource = Me.DsProducts1.Categories
        Me.ComboBox1.DisplayMember = "CategoryName"
        Me.ComboBox1.DropDownWidth = 176
        Me.ComboBox1.Font = New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ComboBox1.Location = New System.Drawing.Point(296, 118)
        Me.ComboBox1.Name = "ComboBox1"
        Me.ComboBox1.Size = New System.Drawing.Size(168, 22)
        Me.ComboBox1.TabIndex = 3
        Me.ComboBox1.Text = "ComboBox1"
        Me.ComboBox1.ValueMember = "CategoryID"
        '
        'DAProducts
        '
        Me.DAProducts.DeleteCommand = Me.SqlDeleteCommand1
        Me.DAProducts.InsertCommand = Me.SqlInsertCommand1
        Me.DAProducts.SelectCommand = Me.SqlSelectCommand1
        Me.DAProducts.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "Products", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("ProductID", "ProductID"), New System.Data.Common.DataColumnMapping("ProductName", "ProductName"), New System.Data.Common.DataColumnMapping("SupplierID", "SupplierID"), New System.Data.Common.DataColumnMapping("CategoryID", "CategoryID"), New System.Data.Common.DataColumnMapping("QuantityPerUnit", "QuantityPerUnit"), New System.Data.Common.DataColumnMapping("UnitPrice", "UnitPrice"), New System.Data.Common.DataColumnMapping("UnitsInStock", "UnitsInStock"), New System.Data.Common.DataColumnMapping("UnitsOnOrder", "UnitsOnOrder"), New System.Data.Common.DataColumnMapping("ReorderLevel", "ReorderLevel"), New System.Data.Common.DataColumnMapping("Discontinued", "Discontinued")})})
        Me.DAProducts.UpdateCommand = Me.SqlUpdateCommand1
        '
        'SqlDeleteCommand1
        '
        Me.SqlDeleteCommand1.CommandText = "DELETE FROM dbo.Products WHERE (ProductID = @ProductID) AND (CategoryID = @Catego" & _
        "ryID OR @CategoryID1 IS NULL AND CategoryID IS NULL) AND (Discontinued = @Discon" & _
        "tinued) AND (ProductName = @ProductName) AND (QuantityPerUnit = @QuantityPerUnit" & _
        " OR @QuantityPerUnit1 IS NULL AND QuantityPerUnit IS NULL) AND (ReorderLevel = @" & _
        "ReorderLevel OR @ReorderLevel1 IS NULL AND ReorderLevel IS NULL) AND (SupplierID" & _
        " = @SupplierID OR @SupplierID1 IS NULL AND SupplierID IS NULL) AND (UnitPrice = " & _
        "@UnitPrice OR @UnitPrice1 IS NULL AND UnitPrice IS NULL) AND (UnitsInStock = @Un" & _
        "itsInStock OR @UnitsInStock1 IS NULL AND UnitsInStock IS NULL) AND (UnitsOnOrder" & _
        " = @UnitsOnOrder OR @UnitsOnOrder1 IS NULL AND UnitsOnOrder IS NULL)"
        Me.SqlDeleteCommand1.Connection = Me.SqlConnection1
        Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@ProductID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "ProductID", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@CategoryID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, True, CType(0, Byte), CType(0, Byte), "CategoryID", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@CategoryID1", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, True, CType(0, Byte), CType(0, Byte), "CategoryID", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Discontinued", System.Data.SqlDbType.Bit, 1, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Discontinued", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@ProductName", System.Data.SqlDbType.NVarChar, 40, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "ProductName", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@QuantityPerUnit", System.Data.SqlDbType.NVarChar, 20, System.Data.ParameterDirection.Input, True, CType(0, Byte), CType(0, Byte), "QuantityPerUnit", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@QuantityPerUnit1", System.Data.SqlDbType.NVarChar, 20, System.Data.ParameterDirection.Input, True, CType(0, Byte), CType(0, Byte), "QuantityPerUnit", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@ReorderLevel", System.Data.SqlDbType.Int, 2, System.Data.ParameterDirection.Input, True, CType(0, Byte), CType(0, Byte), "ReorderLevel", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@ReorderLevel1", System.Data.SqlDbType.Int, 2, System.Data.ParameterDirection.Input, True, CType(0, Byte), CType(0, Byte), "ReorderLevel", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@SupplierID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, True, CType(0, Byte), CType(0, Byte), "SupplierID", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@SupplierID1", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, True, CType(0, Byte), CType(0, Byte), "SupplierID", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@UnitPrice", System.Data.SqlDbType.Money, 8, System.Data.ParameterDirection.Input, True, CType(0, Byte), CType(0, Byte), "UnitPrice", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@UnitPrice1", System.Data.SqlDbType.Money, 8, System.Data.ParameterDirection.Input, True, CType(0, Byte), CType(0, Byte), "UnitPrice", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@UnitsInStock", System.Data.SqlDbType.Int, 2, System.Data.ParameterDirection.Input, True, CType(0, Byte), CType(0, Byte), "UnitsInStock", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@UnitsInStock1", System.Data.SqlDbType.Int, 2, System.Data.ParameterDirection.Input, True, CType(0, Byte), CType(0, Byte), "UnitsInStock", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@UnitsOnOrder", System.Data.SqlDbType.Int, 2, System.Data.ParameterDirection.Input, True, CType(0, Byte), CType(0, Byte), "UnitsOnOrder", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@UnitsOnOrder1", System.Data.SqlDbType.Int, 2, System.Data.ParameterDirection.Input, True, CType(0, Byte), CType(0, Byte), "UnitsOnOrder", System.Data.DataRowVersion.Original, Nothing))
        '
        'SqlSelectCommand1
        '
        Me.SqlSelectCommand1.CommandText = "SELECT ProductID, ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice" & _
        ", UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued FROM dbo.Products"
        Me.SqlSelectCommand1.Connection = Me.SqlConnection1
        '
        'SqlUpdateCommand1
        '
        Me.SqlUpdateCommand1.CommandText = "UPDATE dbo.Products SET ProductName = @ProductName, SupplierID = @SupplierID, Cat" & _
        "egoryID = @CategoryID, QuantityPerUnit = @QuantityPerUnit, UnitPrice = @UnitPric" & _
        "e, UnitsInStock = @UnitsInStock, UnitsOnOrder = @UnitsOnOrder, ReorderLevel = @R" & _
        "eorderLevel, Discontinued = @Discontinued WHERE (ProductID = @Original_ProductID" & _
        ") AND (CategoryID = @Original_CategoryID OR @Original_CategoryID1 IS NULL AND Ca" & _
        "tegoryID IS NULL) AND (Discontinued = @Original_Discontinued) AND (ProductName =" & _
        " @Original_ProductName) AND (QuantityPerUnit = @Original_QuantityPerUnit OR @Ori" & _
        "ginal_QuantityPerUnit1 IS NULL AND QuantityPerUnit IS NULL) AND (ReorderLevel = " & _
        "@Original_ReorderLevel OR @Original_ReorderLevel1 IS NULL AND ReorderLevel IS NU" & _
        "LL) AND (SupplierID = @Original_SupplierID OR @Original_SupplierID1 IS NULL AND " & _
        "SupplierID IS NULL) AND (UnitPrice = @Original_UnitPrice OR @Original_UnitPrice1" & _
        " IS NULL AND UnitPrice IS NULL) AND (UnitsInStock = @Original_UnitsInStock OR @O" & _
        "riginal_UnitsInStock1 IS NULL AND UnitsInStock IS NULL) AND (UnitsOnOrder = @Ori" & _
        "ginal_UnitsOnOrder OR @Original_UnitsOnOrder1 IS NULL AND UnitsOnOrder IS NULL);" & _
        " SELECT ProductID, ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPri" & _
        "ce, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued FROM dbo.Products WHE" & _
        "RE (ProductID = @Select_ProductID)"
        Me.SqlUpdateCommand1.Connection = Me.SqlConnection1
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@ProductName", System.Data.SqlDbType.NVarChar, 40, "ProductName"))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@SupplierID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, True, CType(0, Byte), CType(0, Byte), "SupplierID", System.Data.DataRowVersion.Current, Nothing))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@CategoryID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, True, CType(0, Byte), CType(0, Byte), "CategoryID", System.Data.DataRowVersion.Current, Nothing))

⌨️ 快捷键说明

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