Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using arrays 1

Status
Not open for further replies.

nomu26

Programmer
Sep 10, 2003
22
ZA
how do i insert records in a table that has two-dimensional arrays...
i've never used arrays if someone can help me with this one

cheers
 
declare your array, lets say two-dimensional, as:
int[,] myArray = new int[rowcount, columncount];

to set the values:
for(int i=0; i<rowcount; i++)
{
for(int j=0; j<columncount; j++)
myArray[i,j] = myRecord[i,j];
}
 
the table has created my problem is how do you insert the values in the database and when you opening the page how do you diplay the values on the form...
 
If you have use a "DataTable"/"DataSet", it will automatically keep track of additions/updates/deletions, and you can utilize the "SqlDataAdapter" (or "OleDbDataAdapter") and its "InsertCommand" property in conjuntion with an "SqlCommand" to communicate additions to the database.

As far as displaying the data on a Web Form, you can easily bind a DataTable or DataSet to a DataGrid control using something like this:

Code:
myDataGrid.DataSource = myDataTable;
myDataGrid.DataBind();

For the details, you may have to do a little googling, but post back if you don't find what you need.
 
it's not on a Datagrid format but a table format
 
A DataGrid is rendered as a <table> on the client, it's just that the table is built for you, and it has a bunch of bells and whistles attached (like Events).

You may be crippling yourself if you insist on using a plain old HTML table (assuming there aren't constraints I don't know about). It's much more difficult to keep track of user interactions without the DataGrid.
 
i did try using Datagrid but i was struggling, my form has to diplay more that 20 rows with 8 colums and on of the columns populate a dropdownlistbox and i was struggling to populate the listbox that why i chose to use html table, unless you can help me in using a datagrid
 
The DataGrid is a little tricky to get used to, but once you do, you'll love it.

What you probably want to do is create a DataTable full of your data, and manually create a column on the DataGrid for each column of the DataTable (through the designer).

For the column with the DropDownList, create a TemplateColumn. This looks like a good, pretty simple tutorial on the subject:


When your form posts back, you can hook the ItemCommand (or UpdateCommand, etc.) Event to process the user input.

This looks good:


I am, of course, assuming that your table of data has rows with a common column structure.

All of the DataGrid stuff is, indeed, overwhelming at first, but the time you spend learning it early will pay big-time rewards in your future development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top