CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2008
    Posts
    70

    Datagirdview - clearing rows on recordset

    Hello,
    In my vb 2005, form one combobox and a datagrid view

    datagridview filled via dataset and sqldataadapter - declared class objects

    when an item in the combobox selected, some subitems corresponding to the combobox selecteditem is displayed in the gridview.

    ie., when a new item selected clear the grid and fill the grid from the new record set.


    see the code below

    Dim groupId As Int32
    cmdobj.CommandType = CommandType.StoredProcedure
    cmdobj.CommandText = "select_groupId_on_groupName" : cmdR.Parameters.Clear()
    cmdobj.Parameters.Add("@GroupName", SqlDbType.VarChar, 20, "groupName").Value = GroupName.Text
    groupId = cmdR.ExecuteScalar() : cmdR.Parameters.Clear()

    cmdobj.CommandText = "select_items_onGroupId" : cmdR.Parameters.Clear()
    cmdobj.Parameters.Add("@GroupId", SqlDbType.SmallInt, 0, "groupId").Value = groupId

    adpobj.SelectCommand = cmdobj : adpobj.Fill(dsobj)
    DataGridView1.DataSource = String.Empty : DataGridView1.DataSource = dsobj.Tables(0)

    unfortunately this code not works as I intended, gird not get cleared,

    any help,thanks
    VB.Net 2005, Net Framework 2.0

  2. #2
    Join Date
    Jan 2007
    Posts
    55

    Re: Datagirdview - clearing rows on recordset

    i think if i have got the problem correctly,
    instead of,statement
    DataGridView1.DataSource = String.Empty,
    use
    DataGridView1.DataSource = nothing

    i will suggest
    use filter property of dataset to filter records directly with respective group id,reducing lot of code

    i will definately come up with the code,but try for it first

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Datagirdview - clearing rows on recordset

    Somthing like this would be better.

    Code:
    DataGridView1.DataSource = Nothing
    DataGridView1.Refresh
    DataGridView1.DataSource = dsobj.Tables(0)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

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

Featured