I have a sql server table and i want to read it in the datagrid view of C# .Net.
I think it is easy to do it. but i m not able to show any output in the datagrid...
here is my code.please guide me.where i m wrong..
I think it is easy to do it. but i m not able to show any output in the datagrid...
here is my code.please guide me.where i m wrong..
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace grid
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
DataGrid dataGrid1;
dataGrid1 = new DataGrid();
string strConn, strSQL;
strConn = "server=ABC,Database=test;user id = sa;password=manager;Trusted_Connection=Yes";
strSQL = "select * from info";
SqlDataAdapter da = new SqlDataAdapter(strSQL, strConn);
DataSet ds = new DataSet();
da.Fill(ds, "information");
dataGrid1.DataMember = "info";
dataGrid1.DataSource = ds;
}
}
}
Comment