I have very limited knowledge on asp .net using c#. I am trying to fetch data from my mssql database and display the value on my page. I have succeeded to display it using datagrid. But I want it to diplay attached to labels or text boxes.
Below is the code that I have made but it is throwing error
Below is the code that I have made but it is throwing error
Code:
<%@ Page Language="c#" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
void Page_Load()
{
string connectionStr =
"server=63.45.234.23;uid=MSSqldbdbdb;pwd=password;database=MSSqldbdbdb";
string queryStr = "SELECT * FROM dibs_test";
SqlConnection connectObj = new
SqlConnection(connectionStr);
SqlCommand commandObj = new
SqlCommand(queryStr,connectObj);
SqlDataReader readerObj;
connectObj.Open();
readerObj=commandObj.ExecuteReader();
// display datareader contents into html table
// first open the table and set up the table headers
html += "<table cellspacing=1 class='data' width=90%>";
html += "<tr>";
html += "<th>Customer ID</th>";
html += "<th>Company Name</th>";
html += "</tr>";
// loop thru the reader
while ( readerObj.Read ( ) ) {
html += "<tr>";
html += "<td>" + readerObj.GetInt ( 0 ) + "</td>";
html += "<td>" + readerObj.GetString ( 1 ) + "</td>";
html += "</tr>";
}
// close the table
html += "</table>";
}
</script>
<html>
<head>
<title>Record</title>
</head>
<body>
<h2>Use DataReader to display table with variables not using datagrid
</h2>
<%=html%>
</body>
</html>
</html>
Comment