OleDbParameter Example
using System;
using System.Drawing;
using System.Collections;
using System.Data;
using System.Data.OleDb;
class MainClass{
[STAThread]
static void Main()
{
string cstr = "provider=sqloledb;server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI";
using ( OleDbConnection conn = new OleDbConnection( cstr ) )
{
conn.Open();
string selstr = "select firstName from Employee where lastname = ?";
OleDbCommand cmd = new OleDbCommand( selstr, conn );
OleDbParameter name = cmd.Parameters.Add( "@name", OleDbType.VarChar, 15 );
name.Value = "Tang";
OleDbDataReader rdr = cmd.ExecuteReader();
if ( rdr.Read() )
{
Console.WriteLine(rdr.GetString( 0 ) );
}
else
{
Console.WriteLine(" is not available yet" );
}
}
}
}
|
HTML code for linking to this page:
|