C#/Access-数据库获取自动编号的最大值

//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());

 

http://bbs.csdn.net/topics/390400517?page=1#post-393993079

posted @ 2014-03-26 17:37  dekevin  阅读(1115)  评论(0编辑  收藏  举报