datareader prob
hi all,
I want to fetch records from the database and display them against their labels in a table.
For e.g City: "New Delhi"
so for this i am using datareader as i dont have any other idea (in datagrid i dont think i can display my own labels/text against each record fetched.
Below is my code, am quite confused in using datareader. It is giving error : " Invalid token '(' in class, struct, or interface member declaration"
<%@ Import Namespace="System.Data.SqlClient" %>
<script language="C#" runat="server" > // this script is in my aspx file... no codebehind file used
SqlConnection myConnection = new SqlConnection("server=localhost;database=KTM;uid=s a;pwd=;persist security info=False");
SqlCommand myCommand=new SqlCommand("select * from city_center,city where city.city_id=city_center.city_id",myConnection);
myConnection.Open();//the error is on this line
SqlDataReader dr=myCommand.ExecuteReader();
Response.Write("<table width=550 align=center>")
while (dr.Read())
{
Response.Write("<tr><td>City Name </td><td>"
Response.Write (dr.Item["city_name"])
Response.Write("</td></tr>)"
}
Response.Write ("</table>")
</script>
My aim is to display data in the below format in a table
where Ist column values are hardcoded and second one are fetched from the database.
Ist column II column
City ABC // fetched from database
Phone Phone no //fetched from database
and so on...
Whats the proper method ?
Help of any kind will be appreciated
thanks in advance
Vinay
|