Stupid Question

Y

YYZ

I am using Data for the first time with VB.Net, and it's in an odd way,
so that makes it more strange.

I have created a dataset based on a simple SELECT * FROM Table WHERE
1=0 -- I do that because I don't want any rows returned, only the
structure of what a row would look like. Make sense?

The first thing I want to do is to add a row to the dataset so that I
can run a query against it. I know that sounds strange, but I really
do have a reason for it.

So, Create connection, fine, connect, fine, create dataadapter, fine,
create dataset use the fill of the adapter to fill it (with no rows)
fine.

Adding a row. I can do it by doing this:

dim rowVals(0) as Object
dim row as DAtaRow

row = oDsLoans.Tables("Loans").Rows.Add(rowVals)

After that, row points to something, and it all works great. I know
I'm going to ahve to do this many times in the future, and I really
don't want to have to type out declaring an object array with 1 element
and then use that in the Add statement for the row just to get
something added. However, I can't work out the syntax for something
like this:

row = oDsLoans.Tables("Loans").Rows.Add( x(0) as object) -- see what I
mean - that doesn't work, but I don't need the damn array at all, but
the add function expects an object array to intialize the row variable.
If I could just use the row, I would, but at this point row doesn't
actually point to anything, and I can't figure out how to make a new
row...

Does any of this make sense? Am I doing this correctly at all? Am I
re-inventing some kind of wheel here?

All the examples that I've found for data access in .Net are geared
towards binding. Well, I want to do that, too, in other places, but
not here!

Any help is appreciated.

Matt
 
S

Steve Long

How 'bout this:

workRow = workTable.NewRow()
workRow(0) = I
workRow(1) = "CustName" & I.ToString()
workTable.Rows.Add(workRow)

you can get workTable when you call:
worktable = oDsLoans.Tables("Loans")


HTH
Steve
 
Y

YYZ

workRow = workTable.NewRow()

And we have a winner. That's all I needed. I can't believe I missed
NewRow as a method on the Table object!

Thanks so much -- that is much cleaner in my opinion.

Matt
 

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