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

时间:2023-12-27 15:15:07

//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