1
private void button1_Click(object sender, EventArgs e)
{
    con.Open();
    SqlDataAdapter da = new SqlDataAdapter(
        "select  CustomerName,CompanyName,ContactNo from tbl_LeadFollowUp where WorkType='internet shopping'", con);
    DataSet ds = new DataSet();
    DataTable dt = new DataTable();
    da.Fill(ds);
    da.Fill(dt);

    foreach (DataRow row in dt.Rows)
    {
        textBox1.Text = (row["CompanyName"].ToString());
        textBox2.Text = (row["CustomerName"].ToString());
        label2.Text = (row["ContactNo"].ToString());
     }
     con.close();
}
3
  • Learn databinding and how to use databound control Commented Jul 1, 2016 at 12:06
  • 1
    Is the question here "how do I display multiple rows in the UI?" - because... you're probably going to want a grid of some kind (DataGridView etc) to put the results in... Commented Jul 1, 2016 at 12:06
  • I'm not sure if you are asking for this but, label2.Text += (row["ContactNo"].ToString());. If you want to show multiple data in label (as you told in the question) use this. Commented Jul 1, 2016 at 12:22

1 Answer 1

1

You have to use DataGridview for binding the multiple data from Database to UI.

You can't iterate multiple data to single lable. It will get overwrite not append

private void button1_Click(object sender, EventArgs e)
{
  con.Open();
  SqlDataAdapter da = new SqlDataAdapter("select  CustomerName,CompanyName,ContactNo from tbl_LeadFollowUp where WorkType='internet shopping'", con);
  DataSet ds = new DataSet();
  DataTable dt = new DataTable();
  da.Fill(ds);
  da.Fill(dt);
  dataGridView1.DataSource = da;
  dataGridView1.DataMember = "Lead";
  con.close();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.