Asp.Net Sql ile GridView içine veri almak
using
System.Data.SqlClient;
using
System.Data;System.Data;
SqlConnection con =
new
SqlConnection(
"Server=ServerAdi;Initial Catalog=VeritabaniAdi;User=KullaniciAdi;password=Parola"
);
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!Page.IsPostBack)
{
BindData();
}
}
public
void
BindData()
{
try
{
con.Open();
SqlDataAdapter da =
new
SqlDataAdapter(
"select * from Tablo_Adi"
, con);
DataTable ds =
new
DataTable();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
catch
(Exception ex)
{
lblmsj.Text = ex.Message.ToString();
}
finally
{
con.Close();
}
Kolay gelsin..