如何将datatable中的数据添加到datagridview中显示出来阿?}code=C#]
for(int i =0;i<dt.Rows.Count;i++)
{
DataRow dr =dt.NewRow();
dr[i] = EnoughGridView.ToString();
dt.Rows.Add(dr);
EnoughGridView.DataSource = dt;
[/code]
我运行以后出现错误提示:
输入字符串的格式不正确。不能在 QTY_GET 列中存储 <System.Windows.Forms.DataGridView>。所需类型是 Decimal。
数据库里的字段数据类型是不一样的阿。我该怎么办呢?
或者请指点一下新办法,如何将datatable中的数据添加到datagridview中显示出来解决了就结题,谢谢了
for(int i =0;i<dt.Rows.Count;i++)
{
DataRow dr =dt.NewRow();
dr[i] = EnoughGridView.ToString();
dt.Rows.Add(dr);
EnoughGridView.DataSource = dt;
[/code]
我运行以后出现错误提示:
输入字符串的格式不正确。不能在 QTY_GET 列中存储 <System.Windows.Forms.DataGridView>。所需类型是 Decimal。
数据库里的字段数据类型是不一样的阿。我该怎么办呢?
或者请指点一下新办法,如何将datatable中的数据添加到datagridview中显示出来解决了就结题,谢谢了
SqlConnection conn = new SqlConnection("Data Source=.;User ID=sa;Password=sa;Initial Catalog=Test;");
DataSet ds = new DataSet();
string sql = "select * from Table1";
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
string sql = "select username 用户名 from Table1";
也可以
select username as 用户名 from table
如:select username as 用户名 from 你的表.
datagridview.columns["username"].headtext="用户名";
for(int count=0;count<EnoughGridView.Columns.Count;count++)
{
if(this.EnoughGridView.Columns[count].DataPropertyName=="username")
{
this.EnoughGridView.Columns[count].HeaderText="用户名";
}
}
谢谢了。刚学不久就要干活了,实在是斥力