0

how to display data from SQL database in data gridview using c# .net ?

i found a code on internet but still there is nothing displaying in data gridview https://code.sololearn.com/cmY8A3UQ770z/?ref=app

26th Aug 2017, 8:31 AM
Aamir Naseer
Aamir Naseer - avatar
3 Respostas
+ 1
using System; using System.Data; using System.Windows.Forms; using System.Data.SqlClient; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string connectionString = "Data Source=.;Initial Catalog=pubs;Integrated Security=True"; string sql = "SELECT * FROM Authors"; SqlConnection connection = new SqlConnection(connectionString); SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection); DataSet ds = new DataSet(); connection.Open(); dataadapter.Fill(ds, "Authors_table"); connection.Close(); dataGridView1.DataSource = ds; dataGridView1.DataMember = "Authors_table"; } } }
2nd Feb 2018, 11:28 AM
Habib Ul Bashar
Habib Ul Bashar - avatar
0
asdas
26th Nov 2019, 10:35 AM
juneneil magnanao
juneneil magnanao - avatar
0
its not working men!
26th Nov 2019, 10:36 AM
juneneil magnanao
juneneil magnanao - avatar