Asp. NET connection SQL7 Interface source code

Source: Internet
Author: User

The following example shows what a simple ado.net application which connects to the Northwind database and returns a list O F 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 which connects to the Northwind database and returns a list O F 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 ();

}

}

OLE DB

[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 ();

}

}

Related Article

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.