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

  • SEARCH
  • Home
  • 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 8315825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:13:10+00:00 2026-06-08T21:13:10+00:00

when i click on a button it should save the changes i’ve made to

  • 0

when i click on a button it should save the changes i’ve made to a database, this is the code of the button:

DataRow drow = sql.ds.Tables["Stagiaire"].NewRow();
        Boolean allowAdd = false;
        if (nom.Text != "" && prenom.Text != "")
            allowAdd = true;
        if (allowAdd)
        {
            drow[1] = imgData;
            drow[2] = nom.Text.ToUpper();
            drow[3] = prenom.Text;
            drow[4] = sexe.SelectedItem.ToString();
            drow[5] = naiss.Text;
            drow[6] = email.Text;
            drow[7] = tele.Text;
            drow[8] = adresse.Text;
            drow[9] = niveau.Text;
            drow[10] = filiere.Text;
            drow[11] = stage.SelectedItem.ToString();
            drow[12] = service.SelectedItem.ToString();
            drow[13] = encadrant.SelectedItem.ToString();
            drow[14] = etablissement.SelectedItem.ToString();
            sql.ds.Tables["Stagiaire"].Rows.Add(drow);
            SqlCommandBuilder cmb = new SqlCommandBuilder(daStagiaire);
            daStagiaire.Update(sql.ds, "Stagiaire");
            XtraMessageBox.Show("Bien Ajouter !");
        }

My question is : How can i insert NULL values to the database if the text controllers are empty

  • 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-08T21:13:11+00:00Added an answer on June 8, 2026 at 9:13 pm

    For each of the fields you need to check if the string contains a value. If it has a value, then pass that value, if it does not have a value, then pass the NULL.

    drow[1] = string.IsNullOrWhitespace(imgData)
               ? (object) imgData : DBNull.Value;
    
    drow[2] = string.IsNullOrWhitespace(nom.Text)
               ? (object) nom.Text.ToUpper : DBNull.Value;
    

    … do the same logic to the rest of the items.

    Here I am using a single line IF THEN statement. Take a look at
    One-liner if statements, how to convert this if-else-statement for more information.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET form (C#) but which I click this button that should
When I select values from drop down then click on show button it should
When I click the button the text from the textbox should be written to
My Requiremet is when i Click on first button ,my panel should me me
On click on next button, the list should highlight/select next item in the listview.
Here is what I want to happen: The user should click a link/button that
How can I force validation when user clicks button? One would think this should
I'm trying to update my database records, but no changes are made and no
When I press the Save button I return from my Controller this: return Json(new
Not sure why this isn't working. When people click the 'edit' button of my

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.