none
Using DataGrid RRS feed

  • Question

  • Hi All,

    Iam a beginner in ADO.net..

    When I try to excute the below code,am not getting any output.I created a button in the form with label:'btnUpdate'.This is Implementation of a Disconnected Data Management Strategy.Can anyone explain me what is meant by Disconnected data??and why am i not getting the o/p for the following program.

    Any help is highly appreciated.

    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.Sql;
    using System.Data.SqlClient;
    
    namespace SqlDataAdapter_form
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                const string tablename = "Employees";
    
                InitializeComponent();
    
                btnUpdate.Click += new EventHandler(btnUpdate_Click);
    
                SqlConnection conn = new SqlConnection("Trusted_Connection=yes;" +
                                                       "database=Sample; " +
                                                       "connection timeout=30");
                try
                {
                    conn.Open();
    
    
                    DataGrid datagridEmployees = new DataGrid(); //creating datagrid
    
                    DataSet dataSetEmployees = new DataSet();
    
    
                    datagridEmployees.Location = new Point(5, 5);
                    datagridEmployees.Size = new Size(this.ClientRectangle.Size.Width - 10, this.ClientRectangle.Height - 50);
                    datagridEmployees.DataSource = dataSetEmployees;
                    datagridEmployees.DataMember = tablename;
    
                    SqlDataAdapter dataEmployees = new SqlDataAdapter("select * from Employees", conn);
    
                    SqlCommandBuilder commandEmployees = new SqlCommandBuilder(dataEmployees);
    
                    dataEmployees.Fill(dataSetEmployees, tablename); //filling the dataset
    
                }
                catch (Exception exp)
                {
                    throw exp;
                }
    
                finally
                {
                    conn.Close();
                }
            }
    
            void btnUpdate_Click(object sender, EventArgs e)
            {
               
            }
        }
    }
    




    Thanks,
    Kan

    Tuesday, February 23, 2010 7:10 PM

Answers

All replies

  • I don't know where "disconnected" fits into your scenario, but you're obviously trying to get your data while connected at the moment.

    At first glance, everything looks ok. Is it throwing an exception? One thing you could try is to run a trace with SQL Profiler to see exactly what's getting passed to your SQL Server.


    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    Wednesday, February 24, 2010 5:38 AM
  • Hi can9,

    Did you forget to add your DataGrid to the form?

    this.Controls.Add(datagridEmployees);

    Best regards,
    Alex Liang

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, February 25, 2010 1:22 PM
    Moderator
  • I would take another look at the source of information you're using to learn ADO.NET. The DataAdapter and the (copious) issues associated with it has been replaced by the strongly typed TableAdapter which is far easier to create and deals with these issues. I also wonder why you're not using the Visual Studio GUI designer to place the DataGridView control on the form/page as this automatically generates all of the instantiation and positioning code for you. None of the documentation (or well-written books) would show you examples that have SELECT * in a query--especially without a WHERE clause--at least they shouldn't.
    William (Bill) Vaughn -- Mentor, Author, Dad and MVP
    Thursday, February 25, 2010 10:03 PM
    Moderator