来自数据库的记录未显示在Datagridview上 [英] Record from database did not display on Datagridview
本文介绍了来自数据库的记录未显示在Datagridview上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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;
}
}
}
}
}
推荐答案
请更正您的sql连接字符串,您的datagrid将正常工作,否则,请对datagrid使用数据源连接向导.
Prasad :-D
Please rectify your sql connection string, your datagrid will work, or if else use data source connection wizard for datagrid.
Prasad :-D
连接字符串出了什么问题?实际上我是这里的新手.有人可以拿走我的文件并帮助我吗?
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?
添加以下代码行
dataGridView1.DataBind();
在此行之后dataGridView1.DataSource = tbl;
所以最后两行将成为
dataGridView1.DataSource = tbl;
dataGridView1.DataBind();
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();
这篇关于来自数据库的记录未显示在Datagridview上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文