Previous...
Next....
Here i will explain How to Change column title of datagridview when connecting Sql Server.
Step(1): Form
Drag and down a data Gridview and a Button from tool box.
Step(2): Code
Now click on Botton (Load Button). and write this code
SqlConnection con = new SqlConnection("server = MUNESH;Database=datastore;UID=sa;Password=123;");
SqlCommand cmd = new SqlCommand("Select Eid as 'Employee Id', Name as 'Employee name' , surname as 'Employee surname' ,Age as 'Employee surname' from data1", con);
try
{
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataTable dt = new DataTable();
da.Fill(dt);
BindingSource bsource = new BindingSource ();
bsource .DataSource = dt;
dataGridView1.DataSource = bsource ;
}
catch (Exception ec)
{
MessageBox.Show(ec.Message);
}
Step(3): Run
Now run your application.
Previous...
Next....