【发布时间】:2014-01-26 12:51:25
【问题描述】:
我想在最后一行显示记录摘要的 datagridview 中添加一行。所以我填充我的数据集,然后在其中添加一行,然后将其绑定到 datagridview,然后当我尝试分配我的具有值的新行给了我错误,无法将日期时间转换为字符串,因为第四列数据类型是日期时间。所以我的问题是我们可以更改特定行单元格的列类型,如果没有,那么我该如何实现我想要做的?
string SelectGroupQuery = "Select * From GroupMembers Where GID=@Id ";
using (SqlConnection conGroup = new SqlConnection(ConnectionString.ToString()))
{
using (SqlCommand commandGroup = new SqlCommand(SelectGroupQuery, conGroup))
{
commandGroup.CommandType = CommandType.Text;
commandGroup.Parameters.Add(new SqlParameter("Id", Id));
SqlDataAdapter da = new SqlDataAdapter(commandGroup);
DataSet ds = new DataSet();
da.Fill(ds);
d1 = new DataGridView();
this.Controls.Add(d1);
d1.Location = new Point(50,y);
d1.Size = new Size(600, 300);
dr = ds.Tables[0].NewRow();
ds.Tables[0].Rows.Add(dr);
d1.DataSource = ds.Tables[0];
d1.Columns[4].ValueType = typeof(string);
d1.Rows[d1.Rows.Count-2].Cells[4].Value = "Total Amount";
y = y + 400;
}
}
【问题讨论】:
标签: c# winforms datagridview