We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,599 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Database data isn't showing up on form

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

1
Contributor
1
Reply
5 Minutes
Discussion Span
4 Months Ago
Last Updated
2
Views
silvercats
Posting Pro in Training
410 posts since Apr 2011
Reputation Points: 20
Solved Threads: 2
Skill Endorsements: 0

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

silvercats
Posting Pro in Training
410 posts since Apr 2011
Reputation Points: 20
Solved Threads: 2
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0849 seconds using 2.67MB