|
Question : Convert a DataReader to a DataSet
|
|
I am using VS 2003, .net 1.1. The code below works fine, but I can't page the query results with a datareader. I have tried to use a dataAdapter and dataset but can't get it work. Is there a way of converting the datareader to a dataset. Any help would be appreciated Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load TextBox1.Text = ClaimNo ReinsConn = New OdbcConnection(System.Configuration.ConfigurationSettings.AppSettings("ConnectionString")) ReinsConn.Open() reinsclientcode = "0" Dim polsql As String = "Select claims.code, claims.policy from claims where claims.code=""" & ClaimNo & """" Dim polcmd As New OdbcCommand(polsql, ReinsConn) Dim polReader As OdbcDataReader = polcmd.ExecuteReader(CommandBehavior.CloseConnection) If polReader.HasRows Then While polReader.Read() policy = Trim(polReader.Item(1)).ToString() End While Else End If polReader.Close()
ReinsConn.Open() Dim reinssql As String = "SELECT claims.code, claims.policy," & _ " premsht.policy as mypolicy, premsht.ref_no as ref_no," & _ " premaloc.reinsure as reins, reinsure.desc as reinsdesc," & _ " reinsure.country1 as reinscountry1 from claims" & _ " left join premsht on claims.policy=premsht.policy" & _ " left join premaloc on premsht.ref_no=premaloc.ref_no" & _ " left join reinsure on premaloc.reinsure=reinsure.code" & _ " where premsht.policy + str(sheet_no, 4)" & _ " between padr(""" & Trim(policy) & """, 19) and" & _ " padr(""" & Trim(policy) & """, 15) + ""9999"" and" & _ " claims.code = """ & ClaimNo & """ And " & _ " premaloc.reinsure<>"""" and FSQ=""F"" GROUP BY reins"
Dim reinscmd As New OdbcCommand(reinssql, ReinsConn) Dim reinsReader As OdbcDataReader = reinscmd.ExecuteReader(CommandBehavior.CloseConnection) If reinsReader.HasRows Then DataGrid1.DataSource = reinsReader DataGrid1.DataBind() else reinsReader.Close() ReinsConn.Close()
Response.Redirect("http://localhost/NETTestDocs/Claims/DestQuerystringJune1907.aspx?ClaimNo=" & ClaimNo & " &ClientCode=0" & " &ClientType=Reinsure" & " &ReinsClientCode=0") End If
reinsReader.Close() ReinsConn.Close() End Sub
|
|
Answer : Convert a DataReader to a DataSet
|
|
Try something like this:
Dim table As New DataTable() table.Load(reader)
If that doesn't work, then use an OdbcDataAdapter, and fill a DataTable.
Bob
|
|
|
|