R
Rico
I have some code that was previously working, taking items from one window
and adding them to another. I changed some code around to only add the
dataset tables if no tables exist rather than running a try catch. I
wouldn't think this would have anything to do with setting anything read
only or not, but now when I try to set the "Selected" value in the datatable
(datarow actually) I get "Column 'selected' is read only". When I do a
debug.writeline(MyDs.Tables("TableName").IsReadOnly) the answer is "False".
Is there something I'm missing? Can anyone provide a reason why the datarow
might be read only?
Here are the three items that make up the code;
------ Part One------
Private Sub LoadData()
Dim daOrders As New OleDb.OleDbDataAdapter
Dim LastColumn As String
Try
'Dim sql$ = "SELECT 0 AS Selected,
VendorInventoryTypes.VendorInventoryTypesID, VendorInventoryTypes.Code,
VendorInventoryTypes.Category, VendorInventoryTypes.SubCategory,
VendorInventoryTypes.Brand, VendorInventoryTypes.Model,
VendorInventoryTypes.Description, 0 AS Quantity,
VendorInventoryTypes.RequiresUniqueItems,VendorInventoryTypes.Cost FROM
(VendorInventoryTypes) WHERE (((VendorInventoryTypes.VendorID)=" &
lclVendorID & "));"
If dsInventoryTypeOrders.Tables.Count = 0 Then
Dim sql$ = getOrderDetailSQL("(((VendorInventoryTypes.VendorID)=" &
lclVendorID & "))")
daOrders = mdi.dt.GenericDA(sql)
dsInventoryTypeOrders.Tables.Add("Orders")
daOrders.FillSchema(dsInventoryTypeOrders.Tables("Orders"),
SchemaType.Source)
Dim dc As New DataColumn
dc.AutoIncrement = True
dc.AutoIncrementSeed = -1
dc.AutoIncrementStep = -1
dc.Unique = True
dc.ColumnName = "GUID"
dsInventoryTypeOrders.Tables("Orders").Columns.Add(dc)
dsInventoryTypeOrders.Tables.Add("OrderDetails")
daOrderDetails = mdi.dt.GenericDA("SELECT * FROM VendorOrderItems")
daOrderDetails.FillSchema(dsInventoryTypeOrders.Tables("OrderDetails"),
SchemaType.Source)
dsInventoryTypeOrders.Tables.Add("SerialDetails")
daOrderDetails.FillSchema(dsInventoryTypeOrders.Tables("SerialDetails"),
SchemaType.Source)
daOrderDetails = mdi.dt.GenericDA("SELECT * FROM VendorOrderItems")
daOrderDetails.FillSchema(dsInventoryTypeOrders.Tables("OrderDetails"),
SchemaType.Source)
End If
daOrders.Fill(dsInventoryTypeOrders, "Orders")
view1 = New DataView(dsInventoryTypeOrders.Tables("Orders"))
view1.RowFilter = "Selected = 0"
view2 = New DataView(dsInventoryTypeOrders.Tables("Orders"))
view2.RowFilter = "Selected = 1"
listAvailable.DataSource = view1
listSelected.DataSource = view2
Catch ex As Exception '
MsgBox(ex.Message, MsgBoxStyle.Critical, "VendorEdit.LoadData")
End Try
End Sub
----- Part Two------
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd.Click, listAvailable.DoubleClick
Try
Dim i As Long
Dim r As DataRow
'If nothing is selected or there is nothing in the list, exit
If listAvailable.Items.Count = 0 Or listAvailable.SelectedIndex < 0 Then
Exit Sub
'If the quantity is not numeric then exit
ElseIf Not IsNumeric(txtQuantity.Text) Then
MsgBox("Quantity must be a numeric value.", MsgBoxStyle.Critical, "Non
Numeric Quantity")
Exit Sub
'Ifthe Quantity has a decimal place in it, then exit
ElseIf Fix(txtQuantity.Text) <> txtQuantity.Text Then
MsgBox("Quantity must be an integer.", MsgBoxStyle.Critical, "No Deciman
Places Allowed")
Exit Sub
'if the quantity has a decimal like format, then remove the decimal place
and trailing zero(s)
ElseIf txtQuantity.Text Like "*.*" Then
txtQuantity.Text = Microsoft.VisualBasic.Left(txtQuantity.Text, InStr(1,
txtQuantity.Text, ".") - 1)
End If
' i = listAvailable.SelectedIndex
i = view1(i)("VendorInventoryTypesID")
view1 = dsInventoryTypeOrders.Tables("Orders").DefaultView
view1.RowFilter = "VendorInventoryTypesID=" & i
For Each r In dsInventoryTypeOrders.Tables("Orders").Rows
MsgBox(dsInventoryTypeOrders.Tables("Orders").Rows.IsReadOnly)
If r("VendorInventoryTypesID") = i Then
UpdateRow(Me, r, txtQuantity.Text, True)
End If
Next
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "VendorReceiveOrder.btnAdd_Click")
End Try
End Sub
---- Part Three ----
Friend Sub UpdateRow(ByVal frm As Form, ByVal r As DataRow, ByVal Quantity
As Long, ByVal SelectRow As Boolean)
r.BeginEdit()
' r("Quantity") = Quantity
If SelectRow Then
r("Selected") = 1
Else
r("Selected") = 0
End If
r.AcceptChanges()
UpdateLists()
End Sub
Any help would be great! Thanks!
and adding them to another. I changed some code around to only add the
dataset tables if no tables exist rather than running a try catch. I
wouldn't think this would have anything to do with setting anything read
only or not, but now when I try to set the "Selected" value in the datatable
(datarow actually) I get "Column 'selected' is read only". When I do a
debug.writeline(MyDs.Tables("TableName").IsReadOnly) the answer is "False".
Is there something I'm missing? Can anyone provide a reason why the datarow
might be read only?
Here are the three items that make up the code;
------ Part One------
Private Sub LoadData()
Dim daOrders As New OleDb.OleDbDataAdapter
Dim LastColumn As String
Try
'Dim sql$ = "SELECT 0 AS Selected,
VendorInventoryTypes.VendorInventoryTypesID, VendorInventoryTypes.Code,
VendorInventoryTypes.Category, VendorInventoryTypes.SubCategory,
VendorInventoryTypes.Brand, VendorInventoryTypes.Model,
VendorInventoryTypes.Description, 0 AS Quantity,
VendorInventoryTypes.RequiresUniqueItems,VendorInventoryTypes.Cost FROM
(VendorInventoryTypes) WHERE (((VendorInventoryTypes.VendorID)=" &
lclVendorID & "));"
If dsInventoryTypeOrders.Tables.Count = 0 Then
Dim sql$ = getOrderDetailSQL("(((VendorInventoryTypes.VendorID)=" &
lclVendorID & "))")
daOrders = mdi.dt.GenericDA(sql)
dsInventoryTypeOrders.Tables.Add("Orders")
daOrders.FillSchema(dsInventoryTypeOrders.Tables("Orders"),
SchemaType.Source)
Dim dc As New DataColumn
dc.AutoIncrement = True
dc.AutoIncrementSeed = -1
dc.AutoIncrementStep = -1
dc.Unique = True
dc.ColumnName = "GUID"
dsInventoryTypeOrders.Tables("Orders").Columns.Add(dc)
dsInventoryTypeOrders.Tables.Add("OrderDetails")
daOrderDetails = mdi.dt.GenericDA("SELECT * FROM VendorOrderItems")
daOrderDetails.FillSchema(dsInventoryTypeOrders.Tables("OrderDetails"),
SchemaType.Source)
dsInventoryTypeOrders.Tables.Add("SerialDetails")
daOrderDetails.FillSchema(dsInventoryTypeOrders.Tables("SerialDetails"),
SchemaType.Source)
daOrderDetails = mdi.dt.GenericDA("SELECT * FROM VendorOrderItems")
daOrderDetails.FillSchema(dsInventoryTypeOrders.Tables("OrderDetails"),
SchemaType.Source)
End If
daOrders.Fill(dsInventoryTypeOrders, "Orders")
view1 = New DataView(dsInventoryTypeOrders.Tables("Orders"))
view1.RowFilter = "Selected = 0"
view2 = New DataView(dsInventoryTypeOrders.Tables("Orders"))
view2.RowFilter = "Selected = 1"
listAvailable.DataSource = view1
listSelected.DataSource = view2
Catch ex As Exception '
MsgBox(ex.Message, MsgBoxStyle.Critical, "VendorEdit.LoadData")
End Try
End Sub
----- Part Two------
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd.Click, listAvailable.DoubleClick
Try
Dim i As Long
Dim r As DataRow
'If nothing is selected or there is nothing in the list, exit
If listAvailable.Items.Count = 0 Or listAvailable.SelectedIndex < 0 Then
Exit Sub
'If the quantity is not numeric then exit
ElseIf Not IsNumeric(txtQuantity.Text) Then
MsgBox("Quantity must be a numeric value.", MsgBoxStyle.Critical, "Non
Numeric Quantity")
Exit Sub
'Ifthe Quantity has a decimal place in it, then exit
ElseIf Fix(txtQuantity.Text) <> txtQuantity.Text Then
MsgBox("Quantity must be an integer.", MsgBoxStyle.Critical, "No Deciman
Places Allowed")
Exit Sub
'if the quantity has a decimal like format, then remove the decimal place
and trailing zero(s)
ElseIf txtQuantity.Text Like "*.*" Then
txtQuantity.Text = Microsoft.VisualBasic.Left(txtQuantity.Text, InStr(1,
txtQuantity.Text, ".") - 1)
End If
' i = listAvailable.SelectedIndex
i = view1(i)("VendorInventoryTypesID")
view1 = dsInventoryTypeOrders.Tables("Orders").DefaultView
view1.RowFilter = "VendorInventoryTypesID=" & i
For Each r In dsInventoryTypeOrders.Tables("Orders").Rows
MsgBox(dsInventoryTypeOrders.Tables("Orders").Rows.IsReadOnly)
If r("VendorInventoryTypesID") = i Then
UpdateRow(Me, r, txtQuantity.Text, True)
End If
Next
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "VendorReceiveOrder.btnAdd_Click")
End Try
End Sub
---- Part Three ----
Friend Sub UpdateRow(ByVal frm As Form, ByVal r As DataRow, ByVal Quantity
As Long, ByVal SelectRow As Boolean)
r.BeginEdit()
' r("Quantity") = Quantity
If SelectRow Then
r("Selected") = 1
Else
r("Selected") = 0
End If
r.AcceptChanges()
UpdateLists()
End Sub
Any help would be great! Thanks!