using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
using System.Windows.Forms;
namespace BelediyeProje_58
{
class Veritabani
{
SqlConnection baglanti = null;
SqlCommand command;
public Veritabani()
{
string str = "Data Source=HP;Initial Catalog=BelediyeOtomasyonu;Integrated Security=True";
baglanti = new SqlConnection(str);
try
{ baglanti.Open(); }
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public DataTable SelectSorgusuCalistir(string sSorgu)
{
try
{
if (baglanti.State == ConnectionState.Closed)
baglanti.Open();
SqlDataAdapter da = new SqlDataAdapter(sSorgu, baglanti);
da.SelectCommand.ExecuteNonQuery();
DataTable dt = new DataTable();
da.Fill(dt);
baglanti.Close();
return dt;
}
catch (Exception hata)
{
MessageBox.Show("İşlem Sırasında Hata Oluştu." + hata.Message);
return null;
}
}
public SqlDataReader SendQuery(string query)
{
try
{
query = Splash(query);
command = new SqlCommand(query, baglanti);
return command.ExecuteReader();
}
catch (Exception ex)
{
MessageBox.Show("Hata", ex.Message);
return null;
}
}
public string Splash(string temp)
{
string last = string.Empty;
foreach (char item in temp)
{
if (item == '\\')
{
last = last + '\\' + '\\';
}
else
{
last = last + item;
}
}
return last;
}
public void InsertveUpdateSorgusuCalistir(string sorgu)
{
try
{
if (baglanti.State == ConnectionState.Closed)
baglanti.Open();
SqlCommand com = new SqlCommand(sorgu);
com.CommandType = CommandType.Text;
com.Connection = baglanti;
com.ExecuteNonQuery();
MessageBox.Show("İşlem Tamamlandı",
"Bilgilendirme",
MessageBoxButtons.OK,
MessageBoxIcon.Information,
MessageBoxDefaultButton.Button1);
baglanti.Close();
}
catch (Exception hata)
{
MessageBox.Show("İşlem Sırasında Hata Oluştu." + hata.Message);
}
}
}
}
Veritabani.cs
Veritabani.cs görüntüleniyor.
C# Form Application Database Class Yapısı
Kaydol:
Kayıtlar (Atom)
Hiç yorum yok:
Yorum Gönder