© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago
koopa

SQL Error when trying to get an ID

I'm trying to add username password and email to my users table
And then get the ID of this new user.
            SqlCommand cmd = new SqlCommand("insert into Users values(@username,@password,@email)", cn);
            cmd.Parameters.AddWithValue("username", info["username"]);
            cmd.Parameters.AddWithValue("password", encryptedPW);
            cmd.Parameters.AddWithValue("email", info["email"]);
            int id = (int)cmd.ExecuteScalar();
            SqlCommand cmd = new SqlCommand("insert into Users values(@username,@password,@email)", cn);
            cmd.Parameters.AddWithValue("username", info["username"]);
            cmd.Parameters.AddWithValue("password", encryptedPW);
            cmd.Parameters.AddWithValue("email", info["email"]);
            int id = (int)cmd.ExecuteScalar();

however I get this error:

System.Data.SqlClient.SqlException: 'Column name or number of supplied values does not match table definition.'
System.Data.SqlClient.SqlException: 'Column name or number of supplied values does not match table definition.'
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ IDE error when trying to debug
C#CC# / help
3y ago
Error when trying to write an attribute string using XmlWriter
C#CC# / help
3y ago
❔ Get an entity with Sql data client
C#CC# / help
3y ago
Im getting an error code when trying to call a method.
C#CC# / help
6mo ago