0

My below codes in a button click event
populate data in the grid upon the user click the button.


1. How do I know that my commandtext did not find any matching data to popup the message to the user - No Records found.

2. How do I clear the data in the grid before executing the below codes.


--conection to SQL Server is opened

myadaptor.SelectCommand = New SqlCommand
myadaptor.SelectCommand.Connection = myconection
myadaptor.SelectCommand.CommandText = “--- select ..... where code = ....  ---”
myadaptor.SelectCommand.CommandType = CommandType.Text
myadaptor.Fill(mydataset, "salesdb")
grdlocation.DataSource = mydataset
grdlocation.DataMember = "salesdb"

Edited by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by __avd
0

1. Use the below code

--conection to SQL Server is opened
myadaptor.SelectCommand = New SqlCommand
myadaptor.SelectCommand.Connection = myconection
myadaptor.SelectCommand.CommandText = “--- select ..... where code = .... ---”
myadaptor.SelectCommand.CommandType = CommandType.Text
myadaptor.Fill(mydataset, "salesdb")
If mydataset.Tables(0).Rows.Count > 0 Then
grdlocation.DataSource = mydataset
grdlocation.DataMember = "salesdb"
Else
Label1.Text = "No Records Found"
End If

2. No need to clear the data. Just hide the grid if data not available using its visible property. If data available, just set the same propert to "true".

Edited by murugavel84: n/a

1

>2. How do I clear the data in the grid before executing the below codes.

Set Nothing (null)

grdlocation.DataSource=Nothing
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.