checkbox in dataset

S

Sam

Hi,
I have the following code :

Dim Selectcol As New DataColumn
Dim Updatecol As New DataColumn
Dim Insertcol As New DataColumn

Try
'my own class to fill the dataset (it works)
m_dsFields = da.GetDataset

'add boolean column Select
Selectcol.ColumnName = "Select"
Selectcol.DataType = System.Type.GetType("System.Boolean")
m_dsFields.Tables(0).Columns.Add(Selectcol)


For iCntr As Integer = 0 To m_dsFields.Tables(0).Rows.Count - 1
m_dsFields.Tables(0).Rows(iCntr).Item("Select").value = True
Next
.....

I've got the followin error when the line .....value = True is called:

Field 'value' of type 'DBNull' is 'ReadOnly'."

What's wrong with my code ?

Thx
 
K

Ken Tucker [MVP]

Hi,

Here is an example on how I do it

Dim strConn As String

Dim strSQL As String

Dim daEmployees As OleDbDataAdapter

Dim conn As OleDbConnection

Dim ds As New DataSet

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"

strConn &= "Data Source = Northwind.mdb;"

conn = New OleDbConnection(strConn)

daEmployees = New OleDbDataAdapter("Select * From Employees Order by
LastName, FirstName", conn)

daEmployees.Fill(ds, "Employees")



Dim dcBool As New DataColumn("MyBool", GetType(Boolean))

ds.Tables("Employees").Columns.Add(dcBool)



For Each dr As DataRow In ds.Tables("Employees").Rows

dr.BeginEdit()

dr.Item("MyBool") = True

dr.EndEdit()

Next

DataGrid1.DataSource = ds.Tables("Employees")



Ken

-----------------

Hi,
I have the following code :

Dim Selectcol As New DataColumn
Dim Updatecol As New DataColumn
Dim Insertcol As New DataColumn

Try
'my own class to fill the dataset (it works)
m_dsFields = da.GetDataset

'add boolean column Select
Selectcol.ColumnName = "Select"
Selectcol.DataType = System.Type.GetType("System.Boolean")
m_dsFields.Tables(0).Columns.Add(Selectcol)


For iCntr As Integer = 0 To m_dsFields.Tables(0).Rows.Count - 1
m_dsFields.Tables(0).Rows(iCntr).Item("Select").value = True
Next
.....

I've got the followin error when the line .....value = True is called:

Field 'value' of type 'DBNull' is 'ReadOnly'."

What's wrong with my code ?

Thx
 

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