我在ACCESS里的自增字段加了一个格式,然后以 "GID"00000000 格式自增~为什么在VS绑定 GridView后只显示 自增的数字 1 、 2、 3......
GID00000没有显示出来!原本是想让他显示GID00000001 .....

解决方案 »

  1.   

    在vs里将其格式化,这是格式话的方法, String.Format("{0:D8}",GID)
    具体要灵活运用
      

  2.   

    我换了一个方法不让他自增,我们插入的时候直接指定格式插入~
    方法是这样的:
     public string GetDepartId()
            {
                try
                {
                    DepartModel dm = new DepartModel();
                    DataSet ds = DepartInfo.GetAllDepart(dm);
                    string strDepartId = "";
                    if (ds.Tables["s"].Rows.Count == 0)
                        strDepartId = "DID10000001";
                    else
                        strDepartId = "DID" + (Convert.ToInt32(ds.Tables["s"].Rows[ds.Tables["s"].Rows.Count - 1][0].ToString().Substring(3, 8)) + 1);
                    return strDepartId;
                }
                catch (Exception E)
                {
                    throw E;
                }        }但是这个当插入第二条记录的时候运行是出错了,抛出异常是这样:用户代码未处理 System.ArgumentOutOfRangeException
      Message="startIndex 不能大于字符串长度。\r\n参数名: startIndex"
      Source="BFweb"
      ParamName="startIndex"不懂得怎么解决,高手朋友帮忙看一下。谢谢了~