English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm pretty new to VS Express and all I want to do is to connect to database (SQLServer express) and execute a select statement with a connection like OLEDB or even via ODBC. I don't find convinient to fill my projects with tableadpters etc. Can anyone help or suggest a website? Thanks in advance

2006-06-26 21:21:06 · 1 answers · asked by Louis 3 in Computers & Internet Programming & Design

1 answers

In VS.NET Xpress u can connect with databases using
1.SqlClient, 2. OleDb, 3. Odbc
These classes hav inbuild methods that makes everything simpe and sweet.

For indepth coverage on these topic visit microsoft's MSDN, Also go thru sqljunkies.com, dotnetjunkies.com

OleDb Code Sample
************************************************


using System;
using System.Data;
using System.Data.OleDb;

class Sample
{
public static void Main()
{
OleDbConnection nwindConn = new OleDbConnection("Provider=SQLOLEDB;Data Source=localhost;Integrated Security=SSPI;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();
}
}

Odbc Code Sample
************************************************
using System;
using System.Data;
using System.Data.Odbc;

class Sample
{
public static void Main()
{
OdbcConnection nwindConn = new OdbcConnection("Driver={SQL Server};Server=localhost;" +
"Trusted_Connection=yes;Database=northwind");

OdbcCommand catCMD = new OdbcCommand("SELECT CategoryID, CategoryName FROM Categories", nwindConn);

nwindConn.Open();

OdbcDataReader myReader = catCMD.ExecuteReader();

while (myReader.Read())
{
Console.WriteLine("\t{0}\t{1}", myReader.GetInt32(0), myReader.GetString(1));
}

myReader.Close();
nwindConn.Close();
}
}

2006-06-26 21:56:30 · answer #1 · answered by kalaiguna 2 · 1 0

fedest.com, questions and answers