the following example shows what a simple ado.net application that connects to the northwind database and returns a list of categories would look like. the example writes the output to the console, or command prompt.<br>
<br>
the following example shows what a simple ado.net application that connects to the northwind database and returns a list of categories. the example writes the output to the console, or command prompt.<br>
<br>
sqlclient<br>
[visual basic]<br>
imports system<br>
imports system.data<br>
imports system.data.sqlclient<br>
imports microsoft.visualbasic<br>
<br>
public class sample<br>
<br>
public shared sub main() <br>
dim nwindconn as sqlconnection = new sqlconnection("data source=localhost;" & _<br>
"user id=sa;password=pwd;initial catalog=northwind")<br>
<br>
dim catcmd as sqlcommand = nwindconn.createcommand()<br>
catcmd.commandtext = "select categoryid, categoryname from categories"<br>
<br>
nwindconn.open()<br>
<br>
dim myreader as sqldatareader = catcmd.executereader()<br>
<br>
do while myreader.read()<br>
console.writeline(vbtab & "{0}" & vbtab & "{1}", myreader.getint32(0), myreader.getstring(1))<br>
loop<br>
<br>
myreader.close()<br>
nwindconn.close()<br>
end sub<br>
end class<br>
[c#]<br>
using system;<br>
using system.data;<br>
using system.data.sqlclient;<br>
<br>
class sample<br>
{<br>
public static void main() <br>
{<br>
sqlconnection nwindconn = new sqlconnection("data source=localhost;user id=sa;password=pwd;initial catalog=northwind");<br>
<br>
sqlcommand catcmd = nwindconn.createcommand();<br>
catcmd.commandtext = "select categoryid, categoryname from categories";<br>
<br>
nwindconn.open();<br>
<br>
sqldatareader myreader = catcmd.executereader();<br>
<br>
while (myreader.read())<br>
{<br>
console.writeline("\t{0}\t{1}", myreader.getint32(0), myreader.getstring(1));<br>
}<br>
<br>
myreader.close();<br>
nwindconn.close();<br>
}<br>
}<br>
oledb<br>
[visual basic]<br>
imports system<br>
imports system.data<br>
imports system.data.oledb<br>
imports microsoft.visualbasic<br>
<br>
public class sample<br>
<br>
public shared sub main() <br>
dim nwindconn as oledbconnection = new oledbconnection("provider=sqloledb;data source=localhost;" & _<br>
"user id=sa;password=pwd;initial catalog=northwind")<br>
<br>
dim catcmd as oledbcommand = nwindconn.createcommand()<br>
catcmd.commandtext = "select categoryid, categoryname from categories"<br>
<br>
nwindconn.open()<br>
<br>
dim myreader as oledbdatareader = catcmd.executereader()<br>
<br>
do while myreader.read()<br>
console.writeline(vbtab & "{0}" & vbtab & "{1}", myreader.getint32(0), myreader.getstring(1))<br>
loop<br>
<br>
myreader.close()<br>
nwindconn.close()<br>
end sub<br>
end class<br>
[c#]<br>
using system;<br>
using system.data;<br>
using system.data.oledb;<br>
<br>
class sample<br>
{<br>
public static void main() <br>
{<br>
oledbconnection nwindconn = new oledbconnection("provider=sqloledb;data source=localhost;user id=sa;password=pwd;initial catalog=northwind");<br>
<br>
oledbcommand catcmd = nwindconn.createcommand();<br>
catcmd.commandtext = "select categoryid, categoryname from categories";<br>
<br>
nwindconn.open();<br>
<br>
oledbdatareader myreader = catcmd.executereader();<br>
<br>
while (myreader.read())<br>
{<br>
console.writeline("\t{0}\t{1}", myreader.getint32(0), myreader.getstring(1));<br>
}<br>
<br>
myreader.close();<br>
nwindconn.close();<br>
}<br>
}<br>
ASP。NET连SQL7接口源代码?-.NET教程,Asp.Net开发
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ASP。NET连SQL7接口源代码?-.NET教程,Asp.Net开发
相关推荐
-      VS2010的aspx文件中的html代码的格式化方法
-      .net 反序题目的详细解答第1/2页
-      asp.net创建html文本文件实例
-      比较完整的 asp.net 学习流程
-      官网 Ext direct包中.NET版的问题
-      C# XML操作 代码大全(读XML,写XML,更新,删除节点,与dataset结合等)第1/2页
-      c# 连接字符串数据库服务器端口号 .net状态服务器端口号
-      asp.net教程:简单的C#图片上传代码或C#文件上传代码
