Getting error as Specified cast is not valid
I need to auto inremented id as IDN but Im getting errors in this code.
namespace WebApplication2
{
public partial class WebForm3 : System.Web.UI.Page
{
private void new_id()
{
string ConnString = (@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\koti\Documents\Database11.accdb");
OleDbConnection conn = new OleDbConnection(ConnString);
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
string str = "select max(IDN) from TableMINES";
OleDbCommand cmd = new OleDbCommand(str, conn);
cmd.CommandType = CommandType.Text;
Int32 max = (Int32)cmd.ExecuteScalar();
Label5.Text = (max + 1).ToString();
conn.Close();
}
Can you please help me?