Solved

Trying to manually populate a DataGridView

Posted on 2008-10-05
1
424 Views
Last Modified: 2013-12-17
I am trying to call SetDataSource then Bind the DataSet to the control, but am missing a step.

Could someone tell me how?

Here is  my code so  far:

   public partial class Form1 : Form
    {
        private DataSet dataSet = null;
        private SqlDataAdapter sqlDataAdapter = null;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
        }

        private string ConnectString
        {
            get
            {
                string connectString = "Initial Catalog=ODBCsubsystem;Data Source=(local);Integrated Security=SSPI;";
;
                return connectString;
            }
        }

        private DataSet GetDataSet()
        {
            string sql = null;
            try
            {
                sql = "SELECT * FROM Alerts";

                if (sqlDataAdapter == null || dataSet == null)
                {
                    sqlDataAdapter = new SqlDataAdapter(sql, ConnectString);
                    dataSet = new DataSet();
                    sqlDataAdapter.Fill(dataSet, "Alerts");
                }
                else
                {
                    dataSet.Clear();
                    sqlDataAdapter.Fill(dataSet, "Alerts");
                }
            }
            catch (Exception ex)
            {
            }

            return dataSet;
        }

        private void fillBtn_Click(object sender, EventArgs e)
        {
            dataGridView2.DataSource = GetDataSet();
            dataGridView2.bind  <<<<<<<<<<<<<< how do I bind to the control?
        }
    }
0
Comment
Question by:newbieweb
1 Comment
 
LVL 8

Accepted Solution

by:
rambovn earned 500 total points
ID: 22645359
see this
http://en.csharp-online.net/Working_with_Data%E2%80%94Using_the_DataGridView


try
private void fillBtn_Click(object sender, EventArgs e)
        {
            dataGridView2.DataSource = (GetDataSet()).Tables[0];
           
        }
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now