首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

c# access数据库,字段自动编号,该怎么解决

2013-03-28 
c# access数据库,字段自动编号c# access数据库,某字段自动编号,我想获取自动编号的最大值,要怎么做啊,求详

c# access数据库,字段自动编号
c# access数据库,某字段自动编号,我想获取自动编号的最大值,要怎么做啊,求详细代码啊
[解决办法]
select max(自动编号字段)from table
[解决办法]
         //conStrSQL你改成你的access,我这里用的SQL2005
string conStrSQL = "Data Source=xx.xx.xx.xx;Initial Catalog=xxxxx;User ID=xx;Password=xxxx";
string strSQL = "select max(自动编号字段)from table";
            conn = new SqlConnection(conStrSQL);
            SqlCommand cmd = new SqlCommand(strSQL, conn);
            SqlDataAdapter sda = new SqlDataAdapter();
            sda.SelectCommand = cmd;
            DataSet ds = new DataSet();
            sda.Fill(ds);
MessageBox.Show(ds.Tables[0].Rows[0][0].ToString());
[解决办法]
 public User RetrieveTheLast()
        {
            User user = new User();
            using (IDbConnection conn = Helper.OpenConnection(dataAccess, connectionString))
            {
                   string sql = string.Format("select top 1* from [User] order by ID desc");
                IDataReader reader = dataAccess.ExecuteReader(conn, CommandType.Text, sql, null);
                if (reader.Read())
                {
                    user = BuildUser(reader);
                }
            }
            return user;
        }

热点排行