object cannot be cast from DBNULL to other types model mvc5
<p>I am creating a web app with mvc5 i have multiple users in my database
for eg</p>

<p>USERS</p>

<p>user1) username=ibrahim Password=1ibrahim
user2) username=admin password=4321</p>

<p>when i am logging in from user 1(ibrahim) the page is successfully redirecting to welcome page,
but when i am logging in from user to(admin) the error is coming</p>

<blockquote>
  <p>An exception of type 'System.InvalidCastException' occurred in
  mscorlib.dll but was not handled in user code</p>
  
  <p>Additional information: Object cannot be cast from DBNull to other
  types.</p>
</blockquote>

<p>on <code>user = Convert.ToBoolean(cmd.ExecuteScalar());</code> this line </p>

<p>here is my code</p>

<pre><code>    public class loginuser
    {
        SqlCommand cmd;
        public string role { get; set; }
        public string username { get; set; }
        public string password { get; set; }
        public bool getlogintype(string role, string username, string password)
        {

            string tru = "";
            string fals = "";
            bool user;
            string strname = "";
            SqlConnection con = new SqlConnection("Data Source=erp.hti-india.com,1434;Initial Catalog=erp;Connect Timeout=3600;User Id=erprakesh;Password=14erprakesh14");
            List&lt;object&gt; login = new List&lt;object&gt;();
            if (role == "Admin" || role == "Super Admin" || role !=null)
            {
                cmd = new SqlCommand("select * from [admin] where userid='" + username + "' and pass ='" + password + "'", con);
                con.Open();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                if (dt.Rows.Count &gt; 0)
                {
                    user = true;
                    //HttpContext.Current.Session["userid"] = username.ToString();
                    //HttpContext.Current.Session["tru"] = tru.ToString();
                    // want to redirect to welcome page if condition satisfied.
                }
                else
                {
                    user = false;
                    //want to show the label error message(declare as string errormsg)
                }
                con.Close();
            }
con.Open();
            user = Convert.ToBoolean(cmd.ExecuteScalar());
            con.Close();
            return user;
        }
    }
</code></pre>