Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Trying to manually populate a DataGridView

Posted on 2008-10-05
1
Medium Priority
?
443 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 8

Accepted Solution

by:
rambovn earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

688 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