using System.Data.SqlClient;
using System.Data.Odbc;
public DataTable dt = new DataTable();
//MS Access bağlantı metni ---------------------------------
//string conn_str = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" +// Path.Combine(HostingEnvironment.ApplicationPhysicalPath, @"veritabani.mdb");
//-----------------------------------------------------
//MS SQL bağlantı metni
//public string conn_str = "Server=BS_ismi\\SQLEXPRESS;Database=isim;Trusted_Connection=True";//public string conn_str = "Server=11.11.11.11;Initial Catalog=vt_isim; User Id=isim;Password=sifre";
//-----------------------------------------------------
//MySQL bağlantı metni
//public string conn_str = "Driver={MySQL ODBC 5.1 Driver};Server=11.11.11.11;Database=vt_isim;User=user;Password=sifre;Option=3";// public string conn_str = "Driver={MySQL ODBC 5.1 Driver};Server=127.0.0.1;Database=vt_isim; User=username;Option=3";
public OdbcCommand command = new OdbcCommand(); //MS Access veya MySQL için
public OdbcConnection conn = new OdbcConnection(); //MS Access veya MySQL için
//public SqlConnection conn = new SqlConnection(); //MSSQL için
//public SqlCommand command = new SqlCommand(); //MSSQL için
// SELECT TABLO & SÜTUN İFADELERİ (SEÇME OKUMA)
public DataTable sel(string DB, string columns, string opt){
string komut_s = "Select " + columns + " from " + DB + " " + opt;
DataTable dat = new DataTable();
try
{
conn.ConnectionString = conn_str;
conn.Open();
//SqlDataAdapter adapter = new SqlDataAdapter(komut_s, conn);
OdbcDataAdapter adapter = new OdbcDataAdapter(komut_s, conn);
adapter.Fill(dat);
conn.Close();
//lbl_error.Text = "";
}
catch (Exception ex)
{
//lbl_error.Text = ex.ToString();
}
finally
{
conn.Close();
}
return dat;
}
// INSERT İFADESİ (YENİ VERİ)
public bool ins(string DB, string props, string vals){
bool result = false;
string komut_s = "Insert into " + DB + " (" + props + ") values (" + vals + ")";
try
{
conn.ConnectionString = conn_str;
conn.Open();
command = conn.CreateCommand();
command.CommandText = komut_s;
command.ExecuteNonQuery();
conn.Close();
result = true;
//lbl_error.Text = "";
}
catch (Exception ex)
{
//lbl_error.Text = ex.ToString();
}
finally
{
conn.Close();
}
return result;
}
// UPDATE İFADESİ (GÜNCELLEME)
public bool upd(string DB, string vals, string condition){
bool result = false;
string komut_s = "Update " + DB + " set " + vals + " where " + condition;
try
{
conn.ConnectionString = conn_str;
conn.Open();
command = conn.CreateCommand();
command.CommandText = komut_s;
command.ExecuteNonQuery();
conn.Close();
result = true;
//lbl_error.Text = "";
}
catch (Exception ex)
{
//lbl_error.Text = ex.ToString();
}
finally
{
conn.Close();
}
return result;
}
//DELETE TABLODAN SIRA SİLME İFADESİ
public bool del(string DB, string condition){
bool result = false;
string komut_s = "Delete from " + DB + " where " + condition;
try
{
conn.ConnectionString = conn_str;
conn.Open();
command = conn.CreateCommand();
command.CommandText = komut_s;
command.ExecuteNonQuery();
conn.Close();
//lbl_error.Text = "";
result = true;
}
catch (Exception ex)
{
//lbl_error.Text = ex.ToString();
}
finally
{
conn.Close();
}
return result;
}
// İSTENEN BİR KOMUTU UYGULAMA
public string command_exec(string komut){
string result = "false";
string komut_s = komut;
try
{
conn.ConnectionString = conn_str;
conn.Open();
command = conn.CreateCommand();
command.CommandText = komut_s;
command.ExecuteNonQuery();
conn.Close();
//lbl_error.Text = "";
result = "true";
}
catch (Exception ex)
{
result = ex.ToString();
//lbl_error.Text = ex.ToString();
}
finally
{
conn.Close();
}
return result;
}
//SELECT SCHEMA TABLOLAR İLE İLGİLİ BİLGİ OKUMA vb.
public DataTable sel2(string komut){
string komut_s = komut;
DataTable dat = new DataTable();
try
{
conn.ConnectionString = conn_str;
conn.Open();
//SqlDataAdapter adapter = new SqlDataAdapter(komut_s, conn);
OdbcDataAdapter adapter = new OdbcDataAdapter(komut_s, conn);
adapter.Fill(dat);
conn.Close();
//lbl_error.Text = "";
}
catch (Exception ex)
{
//lbl_error.Text = ex.ToString();
}
finally
{
conn.Close();
}
return dat;
}
Hiç yorum yok:
Yorum Gönder