PDA

View Full Version : asp.net application with recordset


ebco
06-09-2006, 10:44 AM
What is the way by which we can read recordset in asp.net application

otaku149
06-09-2006, 01:23 PM
with asp.net you need to use a datareader or a dataset

ebco
06-10-2006, 07:03 AM
yes that is right. but in current senario i have the recordse xml file stored on server from which i am getting data using asp but now i want to do the same thing with asp.net

ebco
06-10-2006, 01:18 PM
I have found to read recordset using .net from following link
http://www.dotnetcoders.com/web/Articles/ShowArticle.aspx?article=54

I tried it with


but the problem is

what should i write in DBConnection (rs.Open(SQL,DBConnection..)

if i want to access recordset file

otaku149
06-10-2006, 02:28 PM
My suggestion is to access your data directly with a DataSet.

Can you show me your data structure and also how exactly you wish to display the data on your page.

ebco
06-12-2006, 06:47 AM
See this is the way by which i am storing the recordset file on server by using rs.save
<%
const cstring="Provider=SQLOLEDB.1;server=(local);Trusted_Connection=yes;database=databasename;"
set conn=CreateObject("adodb.connection")
conn.Open(cstring)
set rs=CreateObject("adodb.recordset")
rs.ActiveConnection=conn
sq= = "select * from employee"
rs.Open sql,conn,3,1

rs.Save "test.xml"

rs.Close
%>

and this is the way to access the file
<%
paths = Server.MapPath("/test.xml")

set rs_test=server.CreateObject("adodb.recordset")
rs_test.open paths, ,3,1

test_val = rs_test("test")

response.write (test_val)

rs_test.close
%>

now I want to access the same file using .net

I think this will make more clear my question

let me know if u r getting any work around

otaku149
06-12-2006, 01:41 PM
You can use a DataSet and a Repeater to display your .xml file like below:

test.xml

<?xml version="1.0" encoding="utf-8" ?>
<Data>
<employee>
<FirstName>Gabe</FirstName>
<LastName>Newell</LastName>
</employee>
<employee>
<FirstName>Georges</FirstName>
<LastName>Smith</LastName>
</employee>
<employee>
<FirstName>Alan</FirstName>
<LastName>Anderson</LastName>
</employee>
</Data>


sample.aspx

<%@ Page Language="VB" %>
<%@ import Namespace="System.Data" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

Dim DS As New DataSet()
DS.ReadXml(Server.MapPath("test.xml"))
EmpRepeater.DataSource = DS.Tables(0).DefaultView
EmpRepeater.DataBind()

End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>XML Sample</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater id="EmpRepeater" runat="server">
<HeaderTemplate>
<table border="1">
<tr>
<td><b>First Name</b></td>
<td><b>Last Name</b></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td> <%# DataBinder.Eval(Container.DataItem, "FirstName") %> </td>
<td> <%# DataBinder.Eval(Container.DataItem, "LastName") %> </td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>

otaku149
06-12-2006, 02:13 PM
And if you wish to create your xml file using .Net:


<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter

MyConnection = New SqlConnection("server=XXX;database=dbname;uid=yourUserID;pwd=yourPassword;")
MyCommand = New SqlDataAdapter("select * from employee", MyConnection)

DS = New DataSet()
MyCommand.Fill(DS, "employee")
DS.WriteXml(Server.MapPath("test.xml"))

ebco
06-12-2006, 03:53 PM
See the way we are generating the xml's(recordset file) can not be change because there is other huge processes depends upon it & can not be changed that just to make project in .net

that's why i want to use the same recordset file with .net

& the code which u have given me is for pure xml file which giving me error:

hexadecimal value 0x01, is an invalid character.


I think if u can help me out of this!!

otaku149
06-12-2006, 05:50 PM
This usually happen because you have some odd ASCII characters.

Without having you xml file it's hard for me to test but maybe you can try to base64 encode within your recordset and decode using the following .Net function:


Public Function Decode(ByVal str As String) As String
Dim decbuff As Byte() = Convert.FromBase64String(str)
Return System.Text.Encoding.UTF8.GetString(decbuff)
End Function


And call the Decode function directly in your repeater:

<ItemTemplate>
<tr>
<td><%#Decode(DataBinder.Eval(Container.DataItem, "FirstName"))%></td>
<td><%#Decode(DataBinder.Eval(Container.DataItem, "LastName"))%></td>
</tr>
</ItemTemplate>

ebco
06-13-2006, 05:37 AM
if u will try my above mentioned code to create file or use that link u will come to know the file which I am talking about