
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
namespace WindowsFormsApp13
{
class sqlBaglantisiSinifi
{
public SqlConnection baglantiMetodu() // tanımlamış olduğun metot geri değer döndüren bir metot
{
SqlConnection baglan = new SqlConnection (@"Data Source=FP-BIDB-21\SQLEXPRESS;Initial Catalog=ogrenci;Integrated Security=True");
baglan.Open();
return baglan;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApp13
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
sqlBaglantisiSinifi baglantiNesnesi = new sqlBaglantisiSinifi(); // nesne türetiyoruz
SqlDataAdapter da = new SqlDataAdapter("select * from kisiler", baglantiNesnesi.baglantiMetodu());
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
}
}