Results 1 to 5 of 5

Thread: [RESOLVED] Populating datagrid with columns with multiple tables.

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Minnesota
    Posts
    830

    [RESOLVED] Populating datagrid with columns with multiple tables.

    Using ASP.NET (vb), I have two tables and joining on ID. I am having some issues populating my datagrid with a dataset.

    Here is what I have so far:
    VB Code:
    1. Dim conPubs as SqlConnection
    2. Dim dsSearch1 as DataSet
    3. Dim dsSearch2 as DataSet
    4. Dim adSearch1 as SqlDataAdapter
    5. Dim adSearch2 as SqlDataAdapter
    6. Dim iRecordsFound as Integer
    7. Dim sSearch as String
    8.  
    9. conPubs = New SqlConnection(...)
    10.  
    11. sSearch = txtSearch.Text("'", "''")
    12. If sSearch.Length > 0 Then
    13.  sSQL1 = "SELECT PRD_ID, BRAND, MODEL FROM t_products "
    14.  sSQL1 &= "WHERE BRAND like '%" & sSearch & "' "
    15.  sSQL1 &= "ORDER BY BRAND"
    16.  
    17.  sSQL2 = "SELECT RATING, RECOMMEND FROM t_details"
    18. Else
    19.  sSQL1 = "SELECT PRD_ID, BRAND, MODEL FROM t_products "
    20.  sSQL1 &= "ORDER BY BRAND"
    21.  
    22.  sSQL2 = "SELECT RATING, RECOMMEND FROM t_details"
    23. End If
    24.  
    25. adSearch1 = New SqlDataAdapter(sSQL1, conPubs)
    26. adSearch2 = New SqlDataAdapter(sSQL2, conPubs)
    27.  
    28. dsSearch1 = New DataSet()
    29. dsSearch2 = New DataSet()
    30.  
    31. adSearch1.Fill(dsSearch1, "t_products")
    32. adSearch2.Fill(dsSearch2, "t_products")
    33.  
    34. Dim pk1(0) as DataColumn
    35. Dim pk2(0) as DataColumn
    36.  
    37. pk1(0) = dsSearch1.Tables(0).Columns("PRD_ID")
    38. dsSearch1.Tables(0).PrimaryKey = pk1
    39.  
    40. pk2(0) = dsSearch2.Tables(0).Columns("PRD_ID")
    41. dsSearch2.Tables(0).PrimaryKey = pk2
    42.  
    43. dsSearch1.Merge(dsSearch2, false, MissingSchemaAction.Add)
    44.  
    45. conPubs.Open()
    46. iRecordsFound = dsSearch1.Tables("t_products").Rows.Count.ToString()
    47. lblRowCount.Text = iRecordsFound
    48.  
    49. datagridOutput.DataSource = dsSearch1
    50. datagridOutput.DataBind()
    51. conPubs.Close()

    The error I get now is:
    System.ArgumentNullException: 'column' argument cannot be null. Parameter name: column

    Any help would be great or better way of doing this is welcome as well.
    Thanks.
    Last edited by lleemon; Oct 6th, 2005 at 11:37 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width