国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET連SQL7接口源代碼

2024-07-10 13:07:49
字體:
來源:轉載
供稿:網友
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.

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.

sqlclient
[visual basic]
imports system
imports system.data
imports system.data.sqlclient
imports microsoft.visualbasic

public class sample

  public shared sub main()
    dim nwindconn as sqlconnection = new sqlconnection("data source=localhost;" & _
                                                       "user id=sa;password=pwd;initial catalog=northwind")

    dim catcmd as sqlcommand = nwindconn.createcommand()
    catcmd.commandtext = "select categoryid, categoryname from categories"

    nwindconn.open()

    dim myreader as sqldatareader = catcmd.executereader()

    do while myreader.read()
      console.writeline(vbtab & "{0}" & vbtab & "{1}", myreader.getint32(0), myreader.getstring(1))
    loop

    myreader.close()
    nwindconn.close()
  end sub
end class
[c#]
using system;
using system.data;
using system.data.sqlclient;

class sample
{
  public static void main()
  {
    sqlconnection nwindconn = new sqlconnection("data source=localhost;user id=sa;password=pwd;initial catalog=northwind");

    sqlcommand catcmd = nwindconn.createcommand();
    catcmd.commandtext = "select categoryid, categoryname from categories";

    nwindconn.open();

    sqldatareader myreader = catcmd.executereader();

    while (myreader.read())
    {
      console.writeline("/t{0}/t{1}", myreader.getint32(0), myreader.getstring(1));
    }

    myreader.close();
    nwindconn.close();
  }
}
oledb
[visual basic]
imports system
imports system.data
imports system.data.oledb
imports microsoft.visualbasic

public class sample

  public shared sub main()
    dim nwindconn as oledbconnection = new oledbconnection("provider=sqloledb;data source=localhost;" & _
                                                           "user id=sa;password=pwd;initial catalog=northwind")

    dim catcmd as oledbcommand = nwindconn.createcommand()
    catcmd.commandtext = "select categoryid, categoryname from categories"

    nwindconn.open()

    dim myreader as oledbdatareader = catcmd.executereader()

    do while myreader.read()
      console.writeline(vbtab & "{0}" & vbtab & "{1}", myreader.getint32(0), myreader.getstring(1))
    loop

    myreader.close()
    nwindconn.close()
  end sub
end class
[c#]
using system;
using system.data;
using system.data.oledb;

class sample
{
  public static void main()
  {
    oledbconnection nwindconn = new oledbconnection("provider=sqloledb;data source=localhost;user id=sa;password=pwd;initial catalog=northwind");

    oledbcommand catcmd = nwindconn.createcommand();
    catcmd.commandtext = "select categoryid, categoryname from categories";

    nwindconn.open();

    oledbdatareader myreader = catcmd.executereader();

    while (myreader.read())
    {
      console.writeline("/t{0}/t{1}", myreader.getint32(0), myreader.getstring(1));
    }

    myreader.close();
    nwindconn.close();
  }
}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 麟游县| 中牟县| 灵寿县| 博客| 彰化县| 杭锦后旗| 怀化市| 江油市| 富阳市| 榆社县| 安吉县| 益阳市| 凤山县| 东乡| 抚顺县| 东明县| 苍溪县| 龙泉市| 内江市| 清水河县| 钦州市| 台中市| 德阳市| 印江| 成武县| 迭部县| 菏泽市| 泌阳县| 新邵县| 比如县| 云龙县| 舟曲县| 大荔县| 北京市| 白朗县| 沂源县| 普格县| 阿克苏市| 蓬莱市| 东光县| 浦东新区|