hi guys i am trying to fill datagrid from database.I using the following code.Can anyone tell me what am i doing wrong.

public Form1()
        {
            InitializeComponent();
            richTextBox1.Text = "Word: I  \nDefinition:";
            richTextBox3.Text = "Word: I  \nDefinition:";
            label2.Text = "Hindi";
            dateTimePicker1.Visible = false;
            SqlDataAdapter dtadp = new SqlDataAdapter();
            DataTable dtbl = new DataTable();
            dateTimePicker1.Visible = true;
            SqlConnection cn = new SqlConnection(@"Server=208.124.179.197;Database=RTLUser;UID=sa;");
            cn.Open();
            DataSet data = new DataSet();
            string myString = "";
            myString = @"Select word from germanTbl";
            SqlCommand cmd = new SqlCommand(myString, cn);
            SqlDataReader rdr = cmd.ExecuteReader();
            cn.Close();
            dtadp.SelectCommand = cmd;
            dtadp.Fill(data);
            dataGridView2.DataSource = dtbl;
            
            
        }

Your data grid is showing the contents of dtbl. dataGridView2.DataSource = dtbl; But you load the data from your DB to data. dtadp.Fill(data);

Edited 6 Years Ago by nick.crane: n/a

sorry i change dtbl to data, its still empty

Edited 6 Years Ago by sdhawan: wrong ans

This question has already been answered. Start a new discussion instead.