using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;
namespace ConsoleApplication1
{
class @dbconnection
{
private OleDbConnection conn = new OleDbConnection();
void con()
{
conn.ConnectionString = "Provider=SQLOLEDB;Data Source=localhost\\sqlexpress;Integrated Security=SSPI;Initial Catalog=ecg_projectDB2";
conn.Open();
}
public OleDbConnection connection
{
get
{
return conn;
}
}
}
class @test
{
private static string user;
public static string username
{
get
{
return user;
}
set
{
user = value;
}
}
public void getname()
{
OleDbCommand cmd = new OleDbCommand();
dbconnection db = new dbconnection();
cmd.Connection = db.connection;
cmd.CommandText = "select * from ecg_projectDB2.dbo.adminusers where password = 'user'";
cmd.CommandType = CommandType.Text;
OleDbDataReader dr = default(OleDbDataReader);
dr = cmd.ExecuteReader();
if(dr.Read())
{
username = (string)dr["username"];
Console.Write(username);
}
dr.Dispose();
dr.Close();
}
}
}
Connectingto ms sql database using oledb
Page 1 of 11 Replies - 161 Views - Last Post: 01 December 2012 - 10:11 AM
#1
Connectingto ms sql database using oledb
Posted 01 December 2012 - 10:09 AM
i wrote this bit of c# code to go into the database and fetch a username but it keeps on saying the connection is not open but i opened it so i do not understand. This code is written within a class which i call i the main :
Replies To: Connectingto ms sql database using oledb
#2
Re: Connectingto ms sql database using oledb
Posted 01 December 2012 - 10:11 AM
You need tobe opening it after line 48.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote






|