国产探花免费观看_亚洲丰满少妇自慰呻吟_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();
  }
}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 靖宇县| 延边| 丹东市| 汕头市| 依安县| 霸州市| 漯河市| 定边县| 安岳县| 建德市| 延长县| 松桃| 女性| 宁晋县| 皮山县| 曲周县| 定襄县| 青岛市| 金平| 广东省| 渭南市| 吉安市| 木里| 抚远县| 云浮市| 同德县| 奉化市| 杭州市| 芜湖市| 灌云县| 新宁县| 张掖市| 长兴县| 吉水县| 治多县| 黔江区| 海南省| 尉犁县| 格尔木市| 古蔺县| 拜城县|