Hi,
After inserting values into employee table i need to get last generated Id of particulate table.
can you please help me in above shared code.
public SqlConnection con;
private void connection()
{
string constr = ConfigurationManager.ConnectionStrings["DBContext"].ToString();
con = new SqlConnection(constr);
}
public virtual bool InsertEmployee(Employee empObject)
{
try
{
connection();
con.Open();
var affectedRows = con.Execute("insert into Emplpyee (Name,Age,gender)"+
"values(@Name, @Age,@gender)",
new { Name= empObject.Name,
Age= empObject.Age,
gender = empObject.gender,
});
//after inserting records into table i need to get last generated id of emplpoyee table
con.Close();
}
catch (Exception ex)
{
}
}