Link to home
Start Free TrialLog in
Avatar of Auerelio Vasquez
Auerelio VasquezFlag for United States of America

asked on

using the rows in a datagrid to create an array or collection

I'm using an infragistices ultragrid

the name of it is ultragrid1

the grid contains 3 columns: name, table, description

i want to create insert statements for sql server from the values input

i have a constant of the insert statement and i want to append the variables from the ultragrid to form a complete insert statement

so i have these variables

insert1 = 'insert into ......'
insert2 = insert1 + variable(info from the datagrid)


what i'm trying to accomplish is this:

get the values from the rows in the ultragrid and form multiple statements so that i can automotate change requests.

the problem is that i don't know how to get the info from the ultragrid into a collection or array, the amount of values in the grid is going to vary, it may have just 1 or 100 rows, but i want to loop thru every row, create my insert statement, then move to the next. when the value of the grid is blank i want to print my values into a text document. how can i accopmplish this in the easiest way ?

also, how do i get the values from the grid into my collection or variable, being that it's going to be a dynamic number of rows in the grid.


Thanks for any help.
Avatar of b1xml2
b1xml2
Flag of Australia image

1. Use a DataTable
2. Create the schema for the DataTable
3. Get The rows from the DataGrid and add them to the DataTable.
4. Have your DataAdapter ready. You can make this easy using the CommandBuilder
5. pass the datatable into the adapter using the Update Method, and it does it all for you. (1 row or 100 rows, it does not matter)

In short, rather than re-writing the wheel, you are properly using ADO.NET
Avatar of Auerelio Vasquez

ASKER

i'm not sure i understand ? i'm not getting this data from any tables in a db. what i want to do is simply this.

collect information from the user, via the data grid, rather than using text boxes. is there a vb control that simulates a table ? i see this could be done by using a bunch of text boxes, but i'd rather do it in tbale format. that is why i thought of the ultragrid. i simply have a form that says , for a particular change request, append the values requested from a user, and appned them to an insert statment. there may be more than one value , that is why i want to loop thru the grid. does that make more sense ? i dont' relaly need to put thins info into a table
ASKER CERTIFIED SOLUTION
Avatar of Ameerh24
Ameerh24

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Dim connection As New SqlConnection(...)
Dim adapter As SqlDataAdapter = ItemInfo.GetDataAdapter(connection)
Dim myTable As DataTable = ItemInfo.Schema
Dim index As Integer
For index = 0 To DataGrid1.VisibleRowCount - 1
myTable.Rows.Add(New Object() {DataGrid1.Item(index, 0), DataGrid1.Item(index, 1), DataGrid1.Item(index, 2)})
Next
connection.Open
adapter.Update(myTable)
connection.Close