Solved

Trying to manually populate a DataGridView

Posted on 2008-10-05
1
432 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

770 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