Nirmal Roy

Nirmal Roy

  • NA
  • 365
  • 29.6k

Bind DatagridView from database?

Aug 23 2016 12:54 AM
Please See the Attachment.
 
Dear all members,
                          I want to  Bind DatagridView from database just like my Attachment designed
in   Windows Application. C#.
                          How???? (not manual).
                          Please Help.
 
i am using that code.
 
private void binddata()
{
SqlDataAdapter da = new SqlDataAdapter(@"SELECT distinct Sectiontype + ' ' + '['+ Questiontype + ']' + ' ' + 'Attempt Question :-' + ' ' + Attemptquestion + ' ' + 'Total Marks :-' + ' ' + Totalmarks
as 'Groupst', Question,Fullmarks FROM dbo.tbl_QuestionConfig where Subject='C++'
group by Sectiontype + ' ' + '['+ Questiontype + ']' + ' ' + 'Attempt Question :-' + ' ' +
Attemptquestion + ' ' + 'Total Marks :-' + ' ' + Totalmarks ,Question,Fullmarks", con);
DataTable dt = new DataTable();
da.Fill(dt);
con.Close();
if (dt.Rows.Count > 0)
{
dataGridView1.DataSource = dt;
dataGridView1.AutoGenerateColumns = false;
dataGridView1.AllowUserToAddRows = false;

dataGridView1.EnableHeadersVisualStyles = false;
dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.LightSeaGreen;
foreach (DataGridViewRow r in dataGridView1.Rows)
{
r.DefaultCellStyle.BackColor = Color.LightCyan;
}


 

Attachment: datatgrid.rar

Answers (9)