当我在订单输入表单上单击保存时,没有提示任何内容,表单将关闭,因为它应该执行但SQL服务器数据库中没有记录 所以我很久以为我会发布整个代码
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Windows.Forms
Imports System.Xml
Imports System.Configuration
Public Class purchaseorderinput
Public Sub SELECTText(ctr As TextBox)
ctr.SelectionStart = 0
ctr.SelectionLength = Len(ctr.Text)
End Sub
Dim connectionString As String = "Data Source=.\SQLEXPRESS;Initial Catalog=StockMasterv5;Trusted_Connection=True"
' Dim connectionString As New SqlConnection(gstrDSN)
Dim connection As New SqlConnection(connectionString)
Dim cmd As SqlCommand
Dim curDel As Decimal
Dim curCom As Decimal
Dim curFactor As Decimal
Dim strSQL As String
Dim strShop As String
Dim strStock As String
Dim strWarehouse As String
Dim strStockCode As String
Dim delid As Integer
' Create a DataSet
Dim cbodata As New DataSet()
Dim adata As New DataSet()
Dim ddata As New DataSet()
Dim pdata As New DataSet()
Dim bdata As New DataSet()
Dim cdata As New DataSet()
Dim udata As New DataSet()
Private detailsBindingSource As New BindingSource()
Dim edata As New DataSet()
Dim InsertCommand As New SqlCommand
Dim UpdateCommand As New SqlCommand
Dim DeleteCommand As New SqlCommand
Dim StockDataAdapter As New SqlDataAdapter("SELECT * FROM tblStock WHERE StockCode='" & strStock & "') Like '" & strStock & "*'))", connection)
Dim SuppliersDataAdapter As New SqlDataAdapter("SELECT * from tblSuppliers where SupplierRef ='" & strShop & "') LIKE '" & strShop & "*'))", connection)
Dim WarehouseDataAdapter As New SqlDataAdapter("Select * from tblWarehouses WHERE WarehouseRef LIKE '%" & strWarehouse & "%'", connection)
'Dim DeliveryDataAdapter As New SqlDataAdapter("SELECT * from tblDeliveries", connection)
Dim DeliveryIDDA As New SqlDataAdapter("Select Max(DeliveryID) as MaxRef from tblDeliveries ", connection)
Dim useridda As New SqlDataAdapter("SELECT LoginCode from tblEmployee where DefaultEmp = 1", connection)
' Dim SettingsDataAdapter As New SqlDataAdapter("SELECT * from tblCompanyDetails", connection)
Dim SeasonDataAdapter As New SqlDataAdapter("SELECT SeasonName from tblSeasons", connection)
Private Sub PurchaseOrderinput_Load(sender As Object, e As EventArgs) Handles Me.Load
adata.Locale = System.Globalization.CultureInfo.InvariantCulture
cbodata.Locale = System.Globalization.CultureInfo.InvariantCulture
If Form1.txtMode.Text = "NEW" Then myNew()
If Form1.txtMode.Text = "OLD" Then myOld()
If Form1.txtMode.Text = "DELETE" Then myDelete()
Try
connection.Open()
SeasonDataAdapter.Fill(cbodata, "tblSeasons")
' SettingsDataAdapter.Fill(adata, "tblCompanyDetails")
' cboCurrentSeason.DataSource = cbodata
' cboCurrentSeason.DisplayMember = "SeasonName"
' cboCurrentSeason.ValueMember = "SeasonName"
For Each dRow As DataRow In cbodata.Tables("tblSeasons").Rows
cboCurrentSeason.Items.Add(dRow.Item(0).ToString)
Next
connection.Close()
Catch ex As SqlException
Return
End Try
End Sub
Private Sub myNew()
cmdAdd.Text = "Add"
cmdCancel.Text = "Cancel"
cmdClear.Text = "Clear"
' Dim dt As DataTable
Dim DeliveryDataAdapter As New SqlDataAdapter
DataGridView1.ColumnCount = 7
DataGridView1.Columns(0).Name = "LineID"
DataGridView1.Columns(1).Name = "DeliveryID"
DataGridView1.Columns(2).Name = "StockCode"
DataGridView1.Columns(3).Name = "TotalGarments"
DataGridView1.Columns(4).Name = "Totalhangers"
DataGridView1.Columns(5).Name = "TotalBoxes"
DataGridView1.Columns(6).Name = "NetAmount"
DataGridView1.Columns.Item(0).Visible = False
DataGridView1.Columns.Item(1).Visible = False
DataGridView1.Columns.Item(2).HeaderText = "Stock Code"
DataGridView1.Columns.Item(3).HeaderText = "Garments"
DataGridView1.Columns.Item(4).HeaderText = "Hangers"
DataGridView1.Columns.Item(5).HeaderText = "Boxes"
DataGridView1.Columns.Item(6).HeaderText = "Cost"
DataGridView1.Columns.Item(2).Width = "100"
DataGridView1.Columns.Item(3).Width = "80"
DataGridView1.Columns.Item(4).Width = "70"
DataGridView1.Columns.Item(5).Width = "70"
DataGridView1.Columns.Item(6).Width = "80"
End Sub
Private Sub myOld()
Dim DeliveryDataAdapter As New SqlDataAdapter("SELECT * from tblDeliveries", connection)
cmdAdd.Text = "OK"
cmdClear.Visible = False
cmdCancel.Text = "Cancel"
OLDRecord()
End Sub
Private Sub myDelete()
Dim i As Integer
Dim a As String
Dim b As String
i = Form1.DataViewer.CurrentRow.Index
' a = Form1.DataViewer.Item(7, i).Value
' b = Form1.DataViewer.Item(8, i).Value
a = Form1.DataViewer.Item(0, i).Value
b = Form1.DataViewer.Item(0, i).Value
DeleteCommand.Connection = connection
DeleteCommand.Connection.Open()
DeleteCommand.CommandType = CommandType.Text
DeleteCommand.CommandText = "DELETE FROM tblStockMovements WHERE MovementType ='1' AND Reference='" & a & "'"
DeleteCommand.ExecuteNonQuery()
DeleteCommand.Connection.Close()
DeleteCommand.Connection = connection
DeleteCommand.Connection.Open()
DeleteCommand.CommandType = CommandType.Text
DeleteCommand.CommandText = "DELETE FROM tblDeliveries WHERE DeliveryID='" & b & "'"
DeleteCommand.ExecuteNonQuery()
DeleteCommand.Connection.Close()
DeleteCommand.Connection.Open()
DeleteCommand.CommandType = CommandType.Text
DeleteCommand.CommandText = "DELETE FROM tblDeliveryLines WHERE DeliveryID='" & b & "'"
DeleteCommand.ExecuteNonQuery()
DeleteCommand.Connection.Close()
Me.Close()
End Sub
Private Sub cmdAddItem_Click(sender As Object, e As EventArgs) Handles cmdAddItem.Click
Dim rowNum As Integer = DataGridView1.Rows.Add()
' TextBox22.Text = FormatCurrency(TextBox22.Text, 2, TriState.True)
With DataGridView1
.Rows(rowNum).Cells(0).Value = TextBox24.Text
.Rows(rowNum).Cells(1).Value = TextBox12.Text
.Rows(rowNum).Cells(2).Value = TextBox18.Text
.Rows(rowNum).Cells(3).Value = TextBox19.Text
.Rows(rowNum).Cells(4).Value = TextBox20.Text
.Rows(rowNum).Cells(5).Value = TextBox21.Text
.Rows(rowNum).Cells(6).Value = TextBox22.Text
curDel = CDec(textbox6.Text)
curCom = CDec(textbox7.Text)
curFactor = (curDel + curCom)
CalculateTotals()
End With
TextBox24.Text = ""
TextBox18.Text = ""
TextBox19.Text = ""
TextBox20.Text = ""
TextBox21.Text = ""
TextBox22.Text = ""
End Sub
Private Sub TextBox1_LostFocus(sender As Object, e As EventArgs) Handles TextBox1.LostFocus
End Sub
Private Sub txtCommission_LostFocus(sender As Object, e As EventArgs) Handles textbox7.LostFocus
textbox7.Text = FormatCurrency(textbox7.Text, 2, TriState.True)
CalculateTotals()
End Sub
Private Sub txtDeliveryCharge_LostFocus(sender As Object, e As EventArgs) Handles textbox6.LostFocus
textbox6.Text = FormatCurrency(textbox6.Text, 2, TriState.True)
CalculateTotals()
End Sub
Private Sub cmdFindSupplier_Click(sender As Object, e As EventArgs) Handles cmdFindSupplier.Click
If TextBox13.Text = "" Then MsgBox("Please Enter a Supplier Reference", MsgBoxStyle.Information, "Stock Master V2")
If TextBox13.Text <> "" Then FindShop()
End Sub
Public Sub FindShop()
Dim sql As String = "Select * from tblSuppliers where SupplierRef='" & TextBox13.Text & "'"
Dim zdataa As New SqlDataAdapter(sql, connection)
Dim dt As New DataSet
zdataa.Fill(dt, "tblSuppliers")
Dim dr As DataRow = dt.Tables(0).Rows(0)
Try
If dr.Table.Rows.Count - 1 > 0 Then
MsgBox("Please Enter a Supplier Reference", MsgBoxStyle.Critical, "Stock Master v2")
Else
DataGridView2.DataSource = dt.Tables(0)
TextBox14.Text = dr("SupplierName").ToString
End If
Catch ex As SqlException
MsgBox("Please Enter a Supplier Reference", MsgBoxStyle.Critical, "Stock Master v2")
End Try
End Sub
Public Sub FindWarehouse()
Dim sql As String = "Select * from tblWarehouses where WarehouseRef='" & TextBox15.Text & "'"
Dim zdataa As New SqlDataAdapter(sql, connection)
Dim dt As New DataSet
If TextBox15.Text = "" Then
sql = "Select * from tblWarehouses"
End If
zdataa.Fill(dt, "tblWarehouses")
Dim dr As DataRow = dt.Tables(0).Rows(0)
DataGridView2.DataSource = dt.Tables(0)
TextBox17.Text = dr("WarehouseName").ToString
If dr("WarehouseType").ToString = "False" Then TextBox16.Text = "Active"
If dr("WarehouseType").ToString = "True" Then TextBox16.Text = "Long Term"
End Sub
Public Sub FindStock()
Dim sql As String = "Select * from tblStock where SupplierRef='" & TextBox13.Text & "'"
Dim zdataa As New SqlDataAdapter(sql, connection)
Dim dt As New DataSet
If TextBox13.Text = "" Then
MsgBox("Select A Supplier", MsgBoxStyle.Exclamation, "Stock Master v2")
TextBox13.Select()
End If
zdataa.Fill(dt, "tblStock")
Dim dr As DataRow = dt.Tables(0).Rows(0)
DataGridView2.DataSource = dt.Tables(0)
If dr.Table.Rows.Count - 1 > 0 Then
TextBox18.Text = dr("StockCode").ToString
Else
MsgBox("Please Create Stock Record", MsgBoxStyle.Exclamation, "Stock Master v2")
End If
' If dr("WarehouseType").ToString = "False" Then TextBox16.Text = "Active"
'If dr("WarehouseType").ToString = "True" Then TextBox16.Text = "Long Term"
End Sub
Private Sub getStock()
strStock = TextBox18.Text
If Trim(strStock) <> "" Then
connection.Open()
StockDataAdapter.Fill(cdata, "tblStock")
TextBox18.Text = cdata.Tables("tblStock").Rows(0).Item("StockCode")
Else
Call FindStock()
End If
End Sub
Private Sub getWarehouse()
strWarehouse = TextBox15.Text
If Trim(strWarehouse) <> "" Then
connection.Open()
' Dim str As String = "Data Source=.;uid=sa;pwd=123;database=master"
' Dim con As New SqlConnection(str)
' Dim cmd As New SqlCommand("select * from logn where username like '%" + TextBox1.Text + "%'", con)
' Dim Adpt As New SqlDataAdapter(cmd)
' Dim ds As New DataSet()
' If (Adpt.Fill(ds, "logn")) Then
'DataGridView1.DataSource = ds.Tables(0)
'MessageBox.Show("match found")
'Else
' MessageBox.Show("match not found")
'End If
WarehouseDataAdapter.Fill(bdata, "tblWarehouses")
TextBox16.Text = bdata.Tables("tblWarehouses").Rows(0).Item("WarehouseName")
connection.Close()
Else
Call FindWarehouse()
End If
End Sub
Private Sub getshop()
strShop = TextBox13.Text
If Trim(strShop) <> "" Then
connection.Open()
SuppliersDataAdapter.Fill(adata, "tblSuppliers")
TextBox14.Text = adata.Tables("tblSuppliers").Rows(0).Item("ShopName")
Else
Call FindShop()
End If
End Sub
Private Sub TabPage2_Click(sender As Object, e As EventArgs) Handles TabPage2.Click
End Sub
Private Sub cmdFindWarehouse_Click(sender As Object, e As EventArgs) Handles cmdFindWarehouse.Click
FindWarehouse()
End Sub
Private Sub cmdFindStockCode_Click(sender As Object, e As EventArgs) Handles cmdFindStockCode.Click
FindStock()
End Sub
Private Sub TextBox13_LostFocus(sender As Object, e As EventArgs) Handles TextBox13.LostFocus
FindShop()
End Sub
Private Sub TextBox15_LostFocus(sender As Object, e As EventArgs) Handles TextBox15.LostFocus
FindWarehouse()
End Sub
Private Sub TextBox18_LostFocus(sender As Object, e As EventArgs) Handles TextBox18.LostFocus
TextBox1.Text = TextBox18.Text
FindStock()
End Sub
Private Sub cmdAdd_Click(sender As Object, e As EventArgs) Handles cmdAdd.Click
If cmdAdd.Text = "Add" Then AddRecord()
If cmdAdd.Text = "OK" Then Close()
End Sub
Private Function GetNextRef() As Integer
On Error Resume Next
Dim nextref As Integer
DeliveryIDDA.Fill(ddata, "tblDeliveries")
If ddata.Tables("tblDeliveries").Rows Is Nothing Then nextref = "1"
If ddata.Tables("tblDeliveries").Rows.Count > 0 Then nextref = ddata.Tables("tblStockMovements").Rows(0).Item("MaxRef")
TextBox12.Text = nextref + 1
End Function
Public Function AddRecord() As Boolean
Dim blnTran As Boolean
Dim lngNextRef As Integer
AddRecord = False
blnTran = True
'Transfer Out
Dim username As String
Dim stockcode As String
Dim delgarm As String
Dim delhang As String
Dim delbox As String
Dim delnet As String
DeliveryIDDA.Fill(edata, "tblDeliveries")
useridda.Fill(udata, "tblEmployee")
username = udata.Tables(0).Rows(0).Item(0)
Dim STR1 As String
Try
'Dim updatedb As String = " INSERT tblStock SET StockCode = @StockCode,SupplierRef = @SupplierRef,Season = @Season,DeadCode = @DeadCode,DeliveredQtyHangers = @DeliveredQtyHangers,RemoveFromClearance = @RemoveFromClearance,AmountTaken= @AmountTaken, CostValue = @CostValue,PCMarkUp = @PCMarkUp,ZeroQty= @ZeroQty,CreatedBy = @CreatedBy,CreatedDate= @CreatedDate WHERE StockCode = @StockCode"
Dim insertdb As String = "INSERT INTO tblDeliveries(OurRef,SupplierRef,WarehouseRef,Season,TotalGarments,TotalBoxes,TotalHangers,NetAmount,DeliveryCharge,Commission,GrossAmount,DeliveryDate,DeliveryType,ConfirmedDate,Notes,Invoice,Shipper,ShipperInvoice,CreatedBy,CreatedDate) VALUES(@OurRef,@SupplierRef,@WarehouseRef,@Season, @TotalGarments, @TotalBoxes, @TotalHangers,@NetAmount,@DeliveryCharge,@Commission,@GrossAmount, @DeliveryDate,@DeliveryType,@ConfirmedDate, @Notes,@Invoice, @Shipper, @ShipperInvoice,@CreatedBy, @CreatedDate"
Dim connection As New SqlConnection(connectionString)
' Create a DataSet
Me.Validate()
Dim com As New SqlCommand
'Transfer Out
lngNextRef = GetNextRef()
com.Connection = connection
com.Connection.Open()
com.CommandType = CommandType.Text
com.CommandText = insertdb
com.Parameters.Add("@SupplierRef", SqlDbType.NVarChar)
com.Parameters.Add("@OurRef", SqlDbType.NVarChar)
com.Parameters.Add("@WarehouseRef", SqlDbType.NVarChar)
com.Parameters.Add("@Season", SqlDbType.NVarChar)
com.Parameters.Add("@TotalGarments", SqlDbType.Float)
com.Parameters.Add("@TotalBoxes", SqlDbType.NVarChar)
com.Parameters.Add("@TotalHangers", SqlDbType.NVarChar)
com.Parameters.Add("@NetAmount", SqlDbType.NVarChar)
com.Parameters.Add("@DeliveryCharge", SqlDbType.NVarChar)
com.Parameters.Add("@Commission", SqlDbType.NVarChar)
com.Parameters.Add("@GrossAmount", SqlDbType.NVarChar)
com.Parameters.Add("@DeliveryDate", SqlDbType.NVarChar)
com.Parameters.Add("@DeliveryType", SqlDbType.NVarChar)
com.Parameters.Add("@ConfirmedDate", SqlDbType.Date)
com.Parameters.Add("@Notes", SqlDbType.NVarChar)
com.Parameters.Add(" @Invoice", SqlDbType.NVarChar)
com.Parameters.Add("@Shipper", SqlDbType.NVarChar)
com.Parameters.Add("@ShipperInvoice", SqlDbType.NVarChar)
com.Parameters.Add("@CreatedBy", SqlDbType.NVarChar)
com.Parameters.Add("@CreatedDate", SqlDbType.Date)
com.Parameters.Add("@SupplierRef", SqlDbType.NVarChar).Value = TextBox13.Text
com.Parameters("@OurRef").Value = TextBox1.Text
com.Parameters("@WarehouseRef").Value = TextBox15.Text
com.Parameters("@Season").Value = cboCurrentSeason.Text
com.Parameters("@TotalGarments").Value = textbox9.Text
com.Parameters("@TotalBoxes").Value = textbox10.Text
com.Parameters("@TotalHangers").Value = textbox11.Text
com.Parameters("@NetAmount").Value = textbox5.Text
com.Parameters("@DeliveryCharge").Value = textbox6.Text
com.Parameters("@Commission").Value = textbox7.Text
com.Parameters("@GrossAmount").Value = textbox8.Text
com.Parameters("@DeliveryDate").Value = DateTimePicker1.Value
com.Parameters("@DeliveryType").Value = cboType.Text
If cboType.Text = "Confirmed" Then
com.Parameters("@ConfirmedDate").Value = Now
Else
com.Parameters("@ConfirmedDate").Value = ""
End If
com.Parameters("@Notes").Value = TextBox23.Text
com.Parameters(" @Invoice").Value = TextBox4.Text
com.Parameters("@Shipper").Value = TextBox2.Text
com.Parameters("@ShipperInvoice").Value = TextBox3.Text
com.Parameters("@CreatedBy").Value = username
com.Parameters("@CreatedDate").Value = Now
com.ExecuteNonQuery()
com.Connection.Close()
connection.Open()
DeliveryIDDA.Fill(edata, "tblDeliveries")
delid = edata.Tables("tblDeliveries").Rows(0).Item("DeliveryID")
TextBox12.Text = delid
connection.Close()
'Transfer In
com.Connection.Open()
For x As Integer = 0 To DataGridView1.Rows.Count - 1
'Copies1 = DataGridView1.Rows(x).Cells(1).Value
delbox = DataGridView1.Rows(x).Cells(4).Value
stockcode = DataGridView1.Rows(x).Cells(2).Value
delnet = DataGridView1.Rows(x).Cells(6).Value
delgarm = DataGridView1.Rows(x).Cells(3).Value
delhang = DataGridView1.Rows(x).Cells(4).Value
STR1 = "INSERT INTO DeliveryLines(DeliveryID,StockCode,DeliveredQtyGarments,DeliveredQtyBoxes,DeliveredQtyHangers,NetAmount) VALUES (@DeliveryID, @StockCode,@DeliveredQtyGarments,@DeliveredQtyBoxes,@DeliveredQtyHangers,@NetAmount)"
Dim Comm As New SqlCommand(STR1, connection)
Comm.Parameters.Add("@DeliveryID", SqlDbType.NVarChar).Value = delid
Comm.Parameters.Add("@StockCode", SqlDbType.NVarChar).Value = stockcode
Comm.Parameters.Add("@DeliveredQtyGarments", SqlDbType.NVarChar).Value = delgarm
Comm.Parameters.Add("@DeliveredQtyHangers", SqlDbType.Float).Value = delhang
Comm.Parameters.Add("@NetAmount", SqlDbType.Float).Value = delnet
Comm.ExecuteNonQuery()
' DeliveryDataAdapter.Update(Me.edata)
Next
connection.Close()
'Dim updatedb As String = " INSERT tblStock SET StockCode = @StockCode,SupplierRef = @SupplierRef,Season = @Season,DeadCode = @DeadCode,DeliveredQtyHangers = @DeliveredQtyHangers,RemoveFromClearance = @RemoveFromClearance,AmountTaken= @AmountTaken, CostValue = @CostValue,PCMarkUp = @PCMarkUp,ZeroQty= @ZeroQty,CreatedBy = @CreatedBy,CreatedDate= @CreatedDate WHERE StockCode = @StockCode"
Dim insertstocmove As String = " INSERT INTO tblStockMovements (StockCode,SupplierRef,Location,LocationType,MovementQtyHangers,MovementQtyBoxes,MovementDate,MovementValue,Reference,TransferReference,CreatedBy,CreatedDate)VALUES(@StockCode,@SupplierRef,@Location,@LocationType,@MovementQtyHangers,@MovementQtyBoxes,@MovementDate,@MovementValue,@Reference,@TransferReference,@CreatedBy,@CreatedDate)"
' Create a DataSet
Me.Validate()
Dim com4 As New SqlCommand(insertstocmove, connection)
'Transfer Out
lngNextRef = GetNextRef()
com4.Connection.Open()
' com.Parameters.AddWithValue("@StockmovementID", lngNextRef)
com4.Parameters.AddWithValue("@StockCode", TextBox1.Text)
com4.Parameters.AddWithValue("@SupplierRef", TextBox13.Text)
com4.Parameters.AddWithValue("@Location", TextBox15.Text)
com4.Parameters.AddWithValue("@LocationType", TextBox16.Text)
com4.Parameters.AddWithValue("@MovementType", "1")
com4.Parameters.AddWithValue("@MovementQtyHangers", textbox10.Text)
com4.Parameters.AddWithValue("@MovementQtyBoxes", textbox11.Text)
com4.Parameters.AddWithValue("@MovementValue", textbox8.Text)
com4.Parameters.AddWithValue("@Reference", TextBox12.Text)
com4.Parameters.AddWithValue("@TransferReference", TextBox12.Text)
com4.Parameters.AddWithValue("@MovementDate", DateTimePicker1.Value)
com4.Parameters.AddWithValue("@CreatedBy", username)
com4.Parameters.AddWithValue("@CreatedDate", Now)
com4.ExecuteNonQuery()
com4.Connection.Close()
Catch ex As Exception
End Try
AddRecord = True
Exit Function
End Function
Public Sub OLDRecord()
Dim i As Integer
i = Form1.DataViewer.CurrentRow.Index
TextBox12.Text = Form1.DataViewer.Item(0, i).Value
TextBox1.Text = Form1.DataViewer.Item(1, i).Value
TextBox13.Text = Form1.DataViewer.Item(2, i).Value
TextBox14.Text = Form1.DataViewer.Item(3, i).Value
cboCurrentSeason.Text = Form1.DataViewer.Item(3, i).Value.ToString
TextBox15.Text = Form1.DataViewer.Item(5, i).Value
textbox9.Text = Form1.DataViewer.Item(6, i).Value
textbox10.Text = Form1.DataViewer.Item(7, i).Value
textbox11.Text = Form1.DataViewer.Item(8, i).Value
textbox5.Text = Form1.DataViewer.Item(9, i).Value
textbox6.Text = Form1.DataViewer.Item(10, i).Value
textbox7.Text = Form1.DataViewer.Item(11, i).Value
textbox8.Text = Form1.DataViewer.Item(12, i).Value
' DateTimePicker1.Text = Form1.DataViewer.Item(13, i).Value
cboType.Text = Form1.DataViewer.Item(14, i).Value
Label28.Text = Form1.DataViewer.Item(13, i).Value
' TextBox23.Text = Form1.DataViewer.Item(16, i).Value
' TextBox4.Text = Form1.DataViewer.Item(17, i).Value
' TextBox2.Text = Form1.DataViewer.Item(18, i).Value
' TextBox3.Text = Form1.DataViewer.Item(19, i).Value
Try
' Create a DataSet.
Dim data2 As New DataSet()
data2.Locale = System.Globalization.CultureInfo.InvariantCulture
' Add data from the Customers table to the DataSet.
' Add data from the Orders table to the DataSet.
Dim detailsDataAdapter As _
New SqlDataAdapter("SELECT * from tblDeliveryLines Where DeliveryID='" & Form1.txtWatchId.Text & "'", connection)
connection.Open()
detailsDataAdapter.Fill(data2, "tblDeliveryLines")
' Establish a relationship between the two tables.
' Dim relation As New DataRelation("PurchaseOrders", _
' data.Tables("tblDeliveries").Columns("DeliveryID"), _
' data.Tables("tblDeliveryLines").Columns("DeliveryID"))
' data.Relations.Add(relation)
' Bind the master data connector to the Customers table.
' masterBindingSource.DataSource = data
' masterBindingSource.DataMember = "tblDeliveries"
' Bind the details data connector to the master data connector,
' using the DataRelation name to filter the information in the
' details table based on the current row in the master table.
detailsBindingSource.DataSource = data2
detailsBindingSource.DataMember = "tblDeliveryLines"
connection.Close()
' com.Connection.Open()
' For x As Integer = 0 To DataGridView1.Rows.Count - 1
' STR1 = "SELECT * from tblDeliveryLines Where DeliveryID = '" & TextBox12.Text & "'"
'Dim Comm As New SqlDataAdapter(STR1, connection)
' Delivery.Fill(edata, "tblDeliverylines")
DataGridView1.DataSource = data2
DataGridView1.DataMember = "tblDeliveryLines"
DataGridView1.AutoGenerateColumns = True
DataGridView1.Columns.Item(0).Visible = False
DataGridView1.Columns.Item(1).Visible = False
DataGridView1.Columns.Item(2).HeaderText = "Stock Code"
DataGridView1.Columns.Item(3).HeaderText = "Garments"
DataGridView1.Columns.Item(4).HeaderText = "Hangers"
DataGridView1.Columns.Item(5).HeaderText = "Boxes"
DataGridView1.Columns.Item(6).HeaderText = "Cost"
DataGridView1.Columns.Item(2).Width = "100"
DataGridView1.Columns.Item(3).Width = "80"
DataGridView1.Columns.Item(4).Width = "70"
DataGridView1.Columns.Item(5).Width = "70"
DataGridView1.Columns.Item(6).Width = "80"
' Next
' connection.Close()
Catch ex As Exception
End Try
End Sub
End Class
不确定发生了什么以及如何解决此问题