Using JScript.NET to make asp.net Web page Basics Tutorial 6

Source: Internet
Author: User
How to use JScript.NET in asp+ This is our key problem. We will use an example to illustrate this problem.
Accessing the SQL Server database
The first aps+ example is to use the JScript.NET and. NET data access classes to access the SQL Server database.
I'm also going to use the familiar <%%> format to access the authors table in pubs, and I know it's simple but it can reflect some of the new features.
<%@ Import namespace= "System.Data"%>
<%@ Import namespace= "System.Data.SQL"%>
<%@ language= "JScript"%>
<link rel= "STYLESHEET" type= "Text/css" href= "Style.css" >
<%
Setting up a database connection
var myconnection:sqlconnection = new SqlConnection ("server=scripting;uid=sa;pwd=;d atabase=pubs");
Execute Query
var mycommand:sqldatasetcommand = new Sqldatasetcommand ("SELECT * from Authors", MyConnection);
declaring variables
var ds:dataset = new DataSet ();
var mytable:datatable
var mycolumns:columnscollection
var mycol:datacolumn
var myrows:rowscollection
var Myrow:datarow
Getting data through the FillDataSet method
Mycommand.filldataset (ds, "Authors");
MyTable = ds. Tables[0]
%>

<%=ds. Tables[0]. Tablename%>

<br>
<TABLE>
<THEAD>
<TR>
<%
Output the field name at the top of the table
Mycolumns = Mytable.columns
For (MyCol in Mycolumns)
{
%>
<th class= "Spec" >
<%=myCol.ColumnName%>
</TH>
<%
}
%>
</TR>
</THEAD>
<%
Output all the records
Myrows = Mytable.rows
For (Myrow in Myrows)
{
%>
<TR>
<%
for (Var i:int=0;i<mycolumns.count;i++)
{
%>
&LT;TD class= "Spec" >
<%=myRow[i]%>
</TD>
<%
}
%>
</TR>
<%
}
%>
</TABLE>




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.