dataGridView1与ACCESS数据库绑定,Vs2005 EE环境.1、dataGridView1有一列是数据库中的字段时间日期类型,我想往这列的单元格输入空值,请问该怎样做?
有问题的代码:
danDataSet.出入记录.Add出入记录Row(Convert.ToDateTime(日期框.Text), 备注框.Text, Convert.ToDateTime("null"));
---这样做的话,dataGridView1更新数据库后Convert.ToDateTime("null")那栏的日期为:1899-12-30 我希望的结果为这栏什么内容都没有.
2、数据库中主键名为“ID”,递增。我想把主键字段的值(1 2 3 4 5 ...)显示在列标题,请问怎样写代码?3、我用this.出入记录TableAdapter.Update(danDataSet);来把dataGridView1的更改保存到数据库。我想请问这样保存的话,是否dataGridView1中没有被修改过的内容都会被再更新一次到数据库?这样的话ACCESS数据库会变得好大。如果要只把修改过的内容更新到数据库,应该怎么做?4、用SQL语句更改了数据库,我想点击按钮dataGridView1就显示更新后的数据库内容,请教代码。
先谢谢各位!
有问题的代码:
danDataSet.出入记录.Add出入记录Row(Convert.ToDateTime(日期框.Text), 备注框.Text, Convert.ToDateTime("null"));
---这样做的话,dataGridView1更新数据库后Convert.ToDateTime("null")那栏的日期为:1899-12-30 我希望的结果为这栏什么内容都没有.
2、数据库中主键名为“ID”,递增。我想把主键字段的值(1 2 3 4 5 ...)显示在列标题,请问怎样写代码?3、我用this.出入记录TableAdapter.Update(danDataSet);来把dataGridView1的更改保存到数据库。我想请问这样保存的话,是否dataGridView1中没有被修改过的内容都会被再更新一次到数据库?这样的话ACCESS数据库会变得好大。如果要只把修改过的内容更新到数据库,应该怎么做?4、用SQL语句更改了数据库,我想点击按钮dataGridView1就显示更新后的数据库内容,请教代码。
先谢谢各位!
解决方案 »
- C# listview column问题
- 两个问题.哪有那么多需要开发的软件. 和 风险性有多大..
- c#用什么工具建模比较好.可以自动生成代码的.
- C#中有没有哪个组件能处理RAR文件的?处理ZIP好象是可以哦
- 问一个问题,xsd在什么情况比必须用?我做了2年asp.net web 程序都没用过,还有xml,我也用不上啊?怎么回事?
- 怎样在代码中对两个文件进行对比校验
- datagrid显示内容较多的数据问题?
- 怎么样隐藏左边导航栏
- EXCEL导入功能部署到本机IIS后报“外部表不是预期的格式”
- 还是关于ListView,如何将图片放到ListView的ColumnHeader上!?
- 请问怎样监测本机网络的上下行速度?
- 问个比较菜的问题?
http://topic.csdn.net/t/20030424/11/1701862.html
2:ACCESS数据设计时设该字段为自动编号,递增就行
3:说了没有记录并不会更新,请你区分更新与新加
4:最简单的是你刷新绑定
第1点要这样做是因为希望保留后一个时间字段日后再输入.
2.主键放在列上那么你删除几行那么你的id值怎么边。最好不要这么做.放当前的counter数.
是不是行标题, 是的话,看MSDN它把代码写给你了
{
// Paint the row number on the row header.
// The using statement automatically disposes the brush.
using (SolidBrush b = new SolidBrush(dataGridView1.RowHeadersDefaultCellStyle.ForeColor))
{
e.Graphics.DrawString(e.RowIndex.ToString(System.Globalization.CultureInfo.CurrentUICulture), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4);
}
}
if (Convert.ToString(DataBinder.Eval(e.Row.DataItem, "ExpiryDate")).Trim().Length > 0)
{
int iExpiryDate = Convert.ToInt32(Convert.ToString(DataBinder.Eval(e.Row.DataItem, "ExpiryDate")).Substring(0, 4).Trim());
if (iExpiryDate > 1900)
{
((Label)e.Row.FindControl("ExpiryDate")).Text = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "ExpiryDate", "{0:yyyy/MM/dd}"));
}
else
{
((Label)e.Row.FindControl("ExpiryDate")).Text = "";
}
}
else
{
((Label)e.Row.FindControl("ExpiryDate")).Text = "";
}
正解!!!!
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
2,private void grdView_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
e.RowBounds.Location.Y,
this.grdView.RowHeadersWidth,
e.RowBounds.Height); TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
this.grdView.RowHeadersDefaultCellStyle.Font,
rectangle,
this.grdView.RowHeadersDefaultCellStyle.ForeColor,
TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter);
}