1.11M Members

Database data isn't showing up on form

 
0
 
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 Dbconnection
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        SqlDataAdapter da;
        SqlConnection con;
        DataSet ds1;

        private void Form1_Load(object sender, EventArgs e)
        {

            con = new SqlConnection("Data Source=hhh-pc\\sqlexpress;Initial Catalog=employees1;Integrated Security=True");
            con.Open();

            ds1 = new DataSet();
            string sql = "select * from tbl_employee";
            da = new SqlDataAdapter(sql, con);


            da.Fill(ds1, "Worker");
            Navigate_records();
            con.Close();

        }

        private void Navigate_records()
        {
            DataRow dRaw = ds1.Tables["workers"].Rows[0];
            textBox1.Text = dRaw.ItemArray.GetValue(1).ToString();
            textBox2.Text = dRaw.ItemArray.GetValue(2).ToString();
            textBox3.Text = dRaw.ItemArray.GetValue(3).ToString();
            textBox4.Text = dRaw.ItemArray.GetValue(4).ToString();

        }

    }
}

nothing is on the form. my database has data

 
0
 

nevermind. it worked. Had to change "worker" to "workers"

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article