hey i'm planning to display all the datas that is in the database as shown in picture output.bmp........but i can't print the whole thing in the database, instead i could print only the first row in the database as shown in picture database.bmp..........can anyone tell me how to print the whole rows for every columns in the database

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 database
{
    public partial class Form7 : Form
    {
        string sq1;
        SqlCommand cmd1;
        SqlDataReader rd1;
        SqlConnection con;
        string usert = "nid";
        Label[] label;
        int counter = 1;
        public Form7()
        {
            InitializeComponent();
            //checing if labels already arecreatred:
            if (label != null)
              ClearingLabels();

            //next: creating new labels:
            int x = 54;
            int y = 19;
            label = new Label[4];
            con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\PROJECT\\PROJECT\\db_image.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
           
            con.Open();
            sq1 = "select * from users where username='" + usert + "'";
            cmd1 = new SqlCommand(sq1, con);
            rd1 = cmd1.ExecuteReader();
            if (rd1.Read())
            {
                //name1 = rd1[0].ToString();
                //passd1 = rd1[1].ToString();


                for (int i = 0; i < label.Length; i++)
                {
                    label[i] = new Label();
                    label[i].Location = new Point(x, y);
                    label[i].Text = " " + rd1[i].ToString(); //((i + 1) * counter).ToString();
                    this.label[i].Size = new System.Drawing.Size(132, 23);
                    this.Controls.Add(label[i]);

                    //setting new location for the next label:
                    x = x + 138;
                    if (i == 4)
                        y = y + 33;
                }
                rd1.Close();
            }
            //to check that new labels are created:
            counter++;
            //}
            con.Close();
        }
        private void ClearingLabels()
        {
            for (int i = 0; i < label.Length; i++)
            {
                label[i].Text = "";
                this.Controls.Remove(label[i]);
            }
            label = null;
        }
    }
    
}

Use DataGridView to display records and in line 32 you set the length of your label=4
and 4 labels there on the screen

but i don't know what to write over here.......see line 2,15

con.Open();
            sq1 = "select * from users where username='" + usert + "'";
            cmd1 = new SqlCommand(sq1, con);
            rd1 = cmd1.ExecuteReader();
            if (rd1.Read())
            {
                //name1 = rd1[0].ToString();
                //passd1 = rd1[1].ToString();


                for (int i = 0; i < label.Length; i++)
                {
                    label[i] = new Label();
                    label[i].Location = new Point(x, y);
                    label[i].Text = " " + rd1[i].ToString(); //((i + 1) * counter).ToString();
                    this.label[i].Size = new System.Drawing.Size(132, 23);
                    this.Controls.Add(label[i]);

                    //setting new location for the next label:
                    x = x + 138;
                    if (i == 4)
                        y = y + 33;
                }
                rd1.Close();
            }
            //to check that new labels are created:
            counter++;
            //}
            con.Close();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.