Error when adding row to dataset

G

Guest

I have a dataset that I created programmatically and bind to a datagrid.
When I add a row and I .show the form I get an error "Error creating window
handle"

This only happens if I have the code to add the row active. If I comment it
out then the form loads successfully (without any records, obviously).

Below is the code:

'-----------------------------Code Starts
Here----------------------------------

Dim dsCategories As New DataSet
Dim tbl_Categories As New DataTable


tbl_Categories.Columns.Add("CatNumber",
System.Type.GetType("System.String"))
tbl_Categories.Columns.Add("CatName",
System.Type.GetType("System.String"))
tbl_Categories.Columns.Add("CatCode",
System.Type.GetType("System.String"))

Dim drCurRow As DataRow = dsCategories.Tables("tbl_Categories").NewRow
drCurRow("CatNumber") = "1"
drCurRow("CatName") = "Regular"
drCurRow("CatCode") = "110"
dsCategories.Tables("tbl_Categories").Rows.Add(drCurRow)

grdCategories.DataSource = dsCategories

'---------------------------------Code Ends
Here--------------------------------
I Hope this is the right newsgroup to post this.
 
C

Cor Ligthert

Dacuna,

I miss one statement
Dim dsCategories As New DataSet
Dim tbl_Categories As New DataTable

dsCategories.tables.add(tbl_Categories)

Do you have that one somewhere?

I hope this helps?

Cor
 
G

Guest

I noticed that I was that missing, but even after I added that line of code
it did not correct the problem. What DID correct the problem was replacing

Dim drCurRow As DataRow = dsCategories.Tables("tbl_Categories").NewRow

with

Dim drCurRow As DataRow = dsCategories.Tables(0).NewRow

which does not make sense because I would think it would mean the same.

Now I have a datagrid problem/question. Are you familiar with the control?
It has to do with expanding all the way instead of having to click on the
plus sign to expand the view to show the content of the table ( I hope I'm
making sense)

Do you know of a tutorial in how to use the datagrid that I can read through?

THanks,

Danny
 
C

Cor Ligthert

Danny,

I do them error by error, I saw the one I showed you and than I stopped
looking, however did as well not understand why it gave the error, but it is
needed when you use it as datasouce although than you see only that nasty +
and nothing more

When you would have done the change below you would as well have avoided the
error
Dim tbl_Categories As New DataTable("tbl_Categories")

And than to answer your next included question it can be
datasource = dsCategories.tables(0)
or when you have changed is as above
datasource = dsCategories.tables("tbl_Categories")
or when you do not add the datatable at all to the dataset
datasource = tbl_Categories

There are nice samples in the resourcekit for the datagrid, however I know
that there are problems with standard opening the samples, so you have to go
around that. (It are complete projects so easy to find).

VB.net Resource kit
http://msdn.microsoft.com/vbasic/vbrkit/default.aspx

And if you have problems installing the resource kit
http://msdn.microsoft.com/vbasic/vbrkit/faq/#installvdir


I hope this helps?

Cor
 
C

Chris, Master of All Things Insignificant

Regarding having to click the plus sign to expand the view.... How many
tables are you showing in the Grid? If you are just showing one table, then
bind the table to your datagrid and not the dataset. This will make it so
the table shows fully expanded.

Chris
 
G

Guest

Ah...perfect. Good point.

Quite a learning curve from ADO to ADO.NET

Thanks for your help
 

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