new error - Column is read only

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!
 
W

W.G. Ryan - MVP

It looks like the Column in question is the only problem, not the table.
Check the column and see if it's read-only. Is it coming back from the DB
as an expression by any chance? This is a frequent culprit.
"Rico" <r c o l l e n s @ h e m m i n g w a y . c o mREMOVE THIS PART IN
CAPS> wrote in message news:W6hSf.150871$B94.45676@pd7tw3no...
 
R

Rico

Now that you mention it, they are set up in the SQL as manual entries (0 as
Quantity, 0 as Selected), but I'm not sure why it worked before and not now.
Strange. I created a work around by setting the two columns to
readonly=false, but is there a better way to do this?

Rick
 
R

Rico

Thanks WG. I think it might have something to do with the introduction of
the dataadapter, although i was sure it was working after I added the DA.

Thanks for the info!

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top