|
-
January 1st, 2009, 12:22 AM
#1
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
-
January 2nd, 2009, 05:50 AM
#2
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
-
January 2nd, 2009, 08:23 PM
#3
Re: Datagirdview - clearing rows on recordset
Somthing like this would be better.
Code:
DataGridView1.DataSource = Nothing
DataGridView1.Refresh
DataGridView1.DataSource = dsobj.Tables(0)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|