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就显示更新后的数据库内容,请教代码。
先谢谢各位!

解决方案 »

  1.   

    to 3、我用this.出入记录TableAdapter.Update(danDataSet);来把dataGridView1的更改保存到数据库。我想请问这样保存的话,是否dataGridView1中没有被修改过的内容都会被再更新一次到数据库?这样的话ACCESS数据库会变得好大。如果要只把修改过的内容更新到数据库,应该怎么做?没有更新过的记录在update中不会被操作。
      

  2.   

    to 4、用SQL语句更改了数据库,我想点击按钮dataGridView1就显示更新后的数据库内容,请教代码。如果你是通过DataGrid修改的记录,然后用DataAdapter.Update来更新操作,只需要把绑定记录集调用AcceptChanges即可
      

  3.   

    to 2则比较麻烦,参看
    http://topic.csdn.net/t/20030424/11/1701862.html
      

  4.   

    1:不理解你这样的做法
    2:ACCESS数据设计时设该字段为自动编号,递增就行
    3:说了没有记录并不会更新,请你区分更新与新加
    4:最简单的是你刷新绑定
      

  5.   

    To:califord(远方) 
    第1点要这样做是因为希望保留后一个时间字段日后再输入.
      

  6.   

    1.Convert.ToDateTime("null"));有这么 用的么???没有数据直接保存Null了
    2.主键放在列上那么你删除几行那么你的id值怎么边。最好不要这么做.放当前的counter数.
      

  7.   

    我就是想再这个时间日期字段的dataGridView1列里什么也不保存
      

  8.   

    to 2
    是不是行标题, 是的话,看MSDN它把代码写给你了
      

  9.   

    private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
            {
                // 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);
                }
            }
      

  10.   

    to 1 用摸板列
    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 = "";
                    }
      

  11.   

    DateTime是值类型,不能为null的。
      

  12.   

    DateTime是值类型,不能为null的。
    正解!!!!
      

  13.   

    請問在C#的GRID中在輸入資料時如何來計算另外一個欄位如(輸入數量,單價自動統計出金額.請高手指點
      
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
      

  14.   


    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);
            }