Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8473189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:16:50+00:00 2026-06-10T17:16:50+00:00

I have a parameterized query and it was working fine, but when I delete

  • 0

I have a parameterized query and it was working fine, but when I delete de DB and create it again, with the same values and everything, it throws an exception that says it cannot insert value NULL with the value sexo, but all the values are assigned, here it’s the code:

    try{
      var cmdPersona_Log = new SqlCommand();
      cmdPersona_Log.Parameters.Clear();
      cmdPersona_Log.Connection = mySqlConnection;
      cmdPersona_Log.CommandType = CommandType.Text;
      cmdPersona_Log.CommandText = @"INSERT INTO [Tomin].[TominRH].[Persona_Log] "
       + "([Id_Action],[Id_User],[Id_Date],[Id_Entidad],[Nombre],[Paterno],[Materno],[Sexo],[Id_Nacionalidad])"
       + " Values (1, 'Admin', @fecha, @id_entidad, @nombre, @paterno, @materno, @sexo, 52)";
      cmdPersona_Log.Parameters.AddWithValue("@fecha", DateTime.Now);
      cmdPersona_Log.Parameters.AddWithValue("@id_entidad", dbRow["CUENTA"].ToString().Trim());
      cmdPersona_Log.Parameters.AddWithValue("@nombre", nombre ?? string.Empty);
      cmdPersona_Log.Parameters.AddWithValue("@paterno", paterno ?? string.Empty);
      cmdPersona_Log.Parameters.AddWithValue("@materno", materno ?? string.Empty);
      cmdPersona_Log.Parameters.AddWithValue("@sexo", 1);
      cmdPersona_Log.ExecuteNonQuery();
   }
   catch(Exception e) 
   {
      MessageBox.Show(dbRow["CUENTA"] + " Persona_log  " + e.ToString());
   } 

I’ve checked the DB and it doesn’t seem to be the problem, any sugestion??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:16:52+00:00Added an answer on June 10, 2026 at 5:16 pm

    You may be running into a case where AddWithValue isn’t inferring your parameter type of bit properly. Use true/false instead of 1/0:

    cmdPersona_Log.Parameters.AddWithValue("@sexo", true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a parameterized postgresql query that users interact with through a PHP front-end.
I have a parameterized query. Depending on parameter values optimal query plan varies significantly.
I have a weird problem with ExecuteQuery in that it isn't working when performing
I have a parameterized SQL query targetted for SQL2005 which is dynamically created in
I have a query that, basically, says this: SELECT DISTINCT [DB_ID] FROM [TableX] WHERE
I have used parameterized query number of times I know it helps in preventing
I want to use MySQLdb to create a parameterized query such as: serials =
I have a query in a TableAdapter that wrapped this SQL (Oracle SQL, uses
Possible Duplicate: How do I create a PDO parameterized query with a LIKE statement
I have this parameterized query in an Npgsqlcommand: UPDATE raw.geocoding SET the_geom = ST_Transform(ST_GeomFromText('POINT(:longitude

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.