Click to See Complete Forum and Search --> : Datagirdview - clearing rows on recordset


marinajogy
December 31st, 2008, 11:22 PM
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

swaroopbhave
January 2nd, 2009, 04:50 AM
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

dglienna
January 2nd, 2009, 07:23 PM
Somthing like this would be better.

DataGridView1.DataSource = Nothing
DataGridView1.Refresh
DataGridView1.DataSource = dsobj.Tables(0)