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;
            
            
        }

What problem are you having?

I cant see anything in the datagrid .Its empty

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);

sorry i change dtbl to data, its still empty

Its working now i got where i was making mistake.Thanks

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.