This is a migrated thread and some comments may be shown as answers.

Gridview, Paging and DataReader

2 Answers 156 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 16 May 2010, 03:53 PM
I can succesfully bind a datareader object as the datasource for a Radgrid.
Unfortunaltelly, when allowing paging, the pages after page 1 are always empty.

I also tried to store the datareader data in a datatable, same problem:

A standard SQLDataSource works fine, also in DataReader mode.

My code:

 

 



 

'=== Radgrid "Suchresultate" ==============================================================
Dim connString As String
Dim cmdString As String
connString = ConfigurationManager.ConnectionStrings("BwaConnectionString").ConnectionString
cmdString = "SELECT [ArtikelID], [Artikelnummer], [Bezeichnung], [Preis], [Text], [Bild], [Warengruppe], [Einheit] FROM [Artikel] WHERE (([Artikelnummer] LIKE '%' + @Artikelnummer + '%') OR ([Bezeichnung] LIKE '%' + @Bezeichnung + '%') OR ([Text] LIKE '%' + @Text + '%'))"

Dim conn As SqlConnection
Dim cmd As New SqlCommand
conn = New SqlConnection(connString)
cmd = New SqlCommand(cmdString, conn)
conn.Open()

Dim da As New SqlDataAdapter

'--- Querystring "Suche" in String speichern ----------------------------------------------
Dim str_Suche As String
str_Suche = Request.QueryString("Suche")

'--- SqlParameter definieren --------------------------------------------------------------
'--- WICHTIG: Das Command und Connection Objekt muß schon initialisiert und geöffnet sein -
'--- Sonst Fehler bei den SqlParametern!!! ------------------------------------------------
With cmd.Parameters
.Add(New SqlParameter("@Artikelnummer", str_Suche))
.Add(New SqlParameter("@Bezeichnung", str_Suche))
.Add(New SqlParameter("@Text", str_Suche))
End With
'--- SqlParameter definieren E N D E -----------------------------------------------------

'--- DataReader anlegen und zuweisen als Datasource
Dim dr_Suchresultate As SqlDataReader
dr_Suchresultate = cmd.ExecuteReader(CommandBehavior.CloseConnection)

Dim dt_Suchresultate As New DataTable
dt_Suchresultate.Load(dr_Suchresultate)

RadGrid_Suchresultate.DataSource = dt_Suchresultate
RadGrid_Suchresultate.DataBind()
'------------------------------------------------------------------------------------------
'=== Radgrid "Suchresultate" E N D E ======================================================

Can you please give me a hint what to do?

Thanks in advance for your help

Best regards

Thomas

 

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 17 May 2010, 08:26 AM
Hello Thomas,

I have attached a small sample project that runs as expected on my side. Please give it a try and let me know how it goes.

Regards,
Martin
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Thomas
Top achievements
Rank 1
answered on 17 May 2010, 07:29 PM
Hello Martin,

works like a charm now, thank you very much!
Your support is really outstanding.

Best regards

Thomas
Tags
Grid
Asked by
Thomas
Top achievements
Rank 1
Answers by
Martin
Telerik team
Thomas
Top achievements
Rank 1
Share this question
or