SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    namevaluecollection and arraylist in ASP.Net web application 2003

    Hello all,

    I am using the NameValueCollection with the ArrayList
    I have one form which are having 7 fields and one button as "Add".
    When I click on "Add" button, it first creates the row in the datagrid(means it is not saving the data to the database) and adds that row first in the data grid but not in the database.

    The following is my code:


    Dim nvcStudName As New NameValueCollection
    Dim nvcStudAdd As New NameValueCollection
    Dim nvcStudAddSec As New NameValueCollection
    Dim nvcStudCity As New NameValueCollection
    Dim nvcStudState As New NameValueCollection
    Dim nvcStudZip As New NameValueCollection
    Dim nvcStudPh As New NameValueCollection


    Dim arrStudDetails As New ArrayList

    nvcStudName("StudName") = txStudName.Text
    nvcStudAdd("StudAdd") = txtStudAdd.Text
    nvcStudAddSec("StudAddSecond") = txtStudAddSecond.Text
    nvcStudCity("StudCity") = txtcity.Text
    nvcStudState(StudState") = drpState.SelectedValue
    nvcStudZip("StudZip") = txtzip.Text
    nvcStudPh("StudPh") = txtStudPh.Text

    'adding data into arraylist

    arrStudDetails.Add(nvcStudName("StudName"))
    arrStudDetails.Add(nvcStudAdd("studAdd"))
    arrStudDetails.Add(nvcStudAddSec("StudAddSecond"))
    arrStudDetails.Add(nvcStudCity("StudCity"))
    arrStudDetails.Add(nvcStudState("StudState"))
    arrStudDetails.Add(nvcStudZip("StudZip"))
    arrStudDetails.Add(nvcStudPh("StudPh"))


    objDt = New System.Data.DataTable("Student")

    objDt.Columns.Add("Student Name")
    objDt.Columns.Add("Student Address")
    objDt.Columns.Add("Student Address2")
    objDt.Columns.Add("City")
    objDt.Columns.Add("State")
    objDt.Columns.Add("Zip")
    objDt.Columns.Add("Student Phone")


    Session("Student") = objDt

    'binding data to datatable to datagrid

    objDt = Session("Student")

    For i As Integer = 0 To arrStudDetails.Count - 1
    objDr = objDt.NewRow
    If i = 0 Then
    objDr("Student Name") = arrStudDetails(i)
    ElseIf i = 1 Then
    objDr("Student Address") = arrStudDetails(i)
    ElseIf i = 2 Then
    objDr("Student address2") = arrStudDetails(i)
    ElseIf i = 3 Then
    objDr("City") = arrStudDetails(i)
    ElseIf i = 4 Then
    objDr("State") = arrStudDetails(i)
    ElseIf i = 5 Then
    objDr("Zip") = arrStudDetails(i)
    ElseIf i = 6 Then
    objDr("Student Phone") = arrStudDetails(i)
    End If
    Next
    objDt.Rows.Add(objDr)
    Session("Student") = objDt
    DataGrid2.DataSource = objDt
    DataGrid2.DataBind()
    Now in this code,
    when I write objDt.Rows.Add(objDr) after the next statement, then , it takes only the last value in the row.But, when I add this statement inside next and after the endif statement, it everytimes creates the new row for the single value when I first time click on the "add" button(i.e it creates 7 rows for 7 values) but I want to create 1 row for 7 values when I click on "Add" button.


    Please help me out how can I do this.

    I want to add the data in the datagrid first and from datagrid I want it to add it to the database.

    Any help can be appriciated.

    Thanks in advance.

  2. #2
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    please help me out


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •