joanalorensen365
New Member
I have the following method to ensure that an entered username does not already exist.\[code\]protected void checkUsername(object source, ServerValidateEventArgs args){ string connString = "Data Source=server;Initial Catalog=database;User Id=username;Password=password;"; string cmdText = "SELECT COUNT(*) FROM igs_users WHERE username = @username"; using(SqlConnection conn = new SqlConnection(connString)) { conn.Open(); using(SqlCommand cmd = new SqlCommand(cmdText, conn)) { cmd.Parameters.AddWithValue("@username", username); Int32 count = (Int32)cmd.ExecuteScalar(); args.IsValid = true; } }}\[/code\]When I run it, I get the following error.System.ArgumentException was unhandled by user code HResult=-2147024809 Message=No mapping exists from object type System.Web.UI.WebControls.TextBox to a known managed provider native type. Source=System.DataThe debugger gives me this error for the below line.\[code\]Int32 count = (Int32)cmd.ExecuteScalar();\[/code\]Any idea what's wrong with this code?