C# Access veritabanı bağlantısı |
8 Mesajlar | 2.042 Okunma |
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OleDb;
using System.Net;
using System.Net.Mail;
using System.Drawing;
using System.Collections;
using System.Drawing.Drawing2D;
using System.IO;
using System.Drawing.Imaging;
using System.Xml;
using System.Text;
using System.Text.RegularExpressions;
///
/// Summary description for veri
///
public class veri
{
public static string yol = @"Provider=Microsoft.Jet.OleDb.4.0;Data Source=|DataDirectory|\\DBNAME.mdb;Persist Security Info=True";
public static OleDbConnection baglan = new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0;Data Source=|DataDirectory|\\DBNAME.mdb;Persist Security Info=True");
public veri()
{
//
// TODO: Add constructor logic here
//
}
public static string strQuery;
public static OleDbCommand cmd;
public static DataTable dt;
//PARAMETRELİ VERİ ÇEK
public static DataTable tabloParametre(string OleDbstr, OleDbParameterCollection p)
{
OleDbConnection bag = new OleDbConnection(yol);
OleDbCommand komut = new OleDbCommand(OleDbstr, bag);
foreach (OleDbParameter param in p)
komut.Parameters.AddWithValue(param.ParameterName, param.Value);
DataTable dt = new DataTable();
OleDbDataAdapter da = new OleDbDataAdapter(komut);
da.Fill(dt);
return dt;
}
//InsertUpdateData
public static bool InsertUpdateData(OleDbCommand cmd)
{
OleDbConnection con = new OleDbConnection(yol);
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
try
{
con.Open();
cmd.ExecuteNonQuery();
return true;
}
catch (Exception ex)
{
throw new Exception((Convert.ToString(ex.Message)));
}
finally
{
con.Close();
con.Dispose();
}
}
//GetDataTable
public static DataTable GetDataTable(string olecumle)
{
OleDbConnection baglanti = new OleDbConnection(yol);
OleDbDataAdapter dap = new OleDbDataAdapter(olecumle, baglanti);
DataTable dt = new DataTable();
try
{
dap.Fill(dt);
}
catch (Exception ex)
{
throw new Exception((Convert.ToString(ex.Message + "(") + olecumle) + ")");
}
dap.Dispose();
baglanti.Close();
baglanti.Dispose();
return dt;
}
}
gencwebciadam adlı üyeden alıntı
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OleDb;
using System.Net;
using System.Net.Mail;
using System.Drawing;
using System.Collections;
using System.Drawing.Drawing2D;
using System.IO;
using System.Drawing.Imaging;
using System.Xml;
using System.Text;
using System.Text.RegularExpressions;
///
/// Summary description for veri
///
public class veri
{
public static string yol = @"Provider=Microsoft.Jet.OleDb.4.0;Data Source=|DataDirectory|\\DBNAME.mdb;Persist Security Info=True";
public static OleDbConnection baglan = new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0;Data Source=|DataDirectory|\\DBNAME.mdb;Persist Security Info=True");
public veri()
{
//
// TODO: Add constructor logic here
//
}
public static string strQuery;
public static OleDbCommand cmd;
public static DataTable dt;
//PARAMETRELİ VERİ ÇEK
public static DataTable tabloParametre(string OleDbstr, OleDbParameterCollection p)
{
OleDbConnection bag = new OleDbConnection(yol);
OleDbCommand komut = new OleDbCommand(OleDbstr, bag);
foreach (OleDbParameter param in p)
komut.Parameters.AddWithValue(param.ParameterName, param.Value);
DataTable dt = new DataTable();
OleDbDataAdapter da = new OleDbDataAdapter(komut);
da.Fill(dt);
return dt;
}
//InsertUpdateData
public static bool InsertUpdateData(OleDbCommand cmd)
{
OleDbConnection con = new OleDbConnection(yol);
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
try
{
con.Open();
cmd.ExecuteNonQuery();
return true;
}
catch (Exception ex)
{
throw new Exception((Convert.ToString(ex.Message)));
}
finally
{
con.Close();
con.Dispose();
}
}
//GetDataTable
public static DataTable GetDataTable(string olecumle)
{
OleDbConnection baglanti = new OleDbConnection(yol);
OleDbDataAdapter dap = new OleDbDataAdapter(olecumle, baglanti);
DataTable dt = new DataTable();
try
{
dap.Fill(dt);
}
catch (Exception ex)
{
throw new Exception((Convert.ToString(ex.Message + "(") + olecumle) + ")");
}
dap.Dispose();
baglanti.Close();
baglanti.Dispose();
return dt;
}
}