Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace CIMBCashFlowApp
{
    public partial class MainMenu : Form
    {
        public MainMenu(string loginType)
        {
            InitializeComponent();
            FillData();
        }

        private void FillData()
        {
            using (SqlConnection con = new SqlConnection
                (Properties.Settings.Default.CIMBFlexiLoanDatabaseConnectionString))
            {
                con.Open();
                using (SqlDataAdapter data = new SqlDataAdapter("SELECT * FROM CIMBFlexiLoanTBL", con))
                {
                    DataTable tbl = new DataTable();
                    data.Fill(tbl);
                    dataGridView1.DataSource = tbl;
                }
            }
        }
    }
}
Posted
Comments
LittleYellowBird 4-Aug-10 5:46am    
Hi, you forgot to actually ask a question. It would also help if explain what you have tried to solve it. :)
Simon_Whale 4-Aug-10 6:24am    
Does your query actually work?
Prasad Bansi Vagal 4-Aug-10 8:30am    
Reason for my vote of 5
goog question
koool.kabeer 5-Aug-10 5:34am    
are there any records in your Database Table

Please rectify your sql connection string, your datagrid will work, or if else use data source connection wizard for datagrid.

Prasad :-D
 
Share this answer
 
what is wrong with the connection string? actually I am a newbie here. is it possible if someone can take my files and help me out?
 
Share this answer
 
Add the following lines of code
dataGridView1.DataBind();
After this line dataGridView1.DataSource = tbl;

So the last 2 lines will become

dataGridView1.DataSource = tbl;
dataGridView1.DataBind();
 
Share this answer
 
I'm sorry but I can't find DataBind() method from dataGridView1.
My code is for window application. DataBind() is for webform?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900