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 7026947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:11:03+00:00 2026-05-28T00:11:03+00:00

So I’ve got a control that has all different user inputs (comboBox, textBox, DatePicker,

  • 0

So I’ve got a control that has all different user inputs (comboBox, textBox, DatePicker, etc.). What I would like is to update a database table “Receipts” with a new row each time the ‘Save’ or ‘Save & Close’ button is clicked.

For each object, I have a data binding to the source. This isn’t throwing any syntactical errors, but that obviously doesn’t mean its right. Here is an example:

this.textBox2.Location = new System.Drawing.Point(73, 150);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(198, 20);
this.textBox2.TabIndex = 15;
this.textBox2.DataBindings.Add("text", ds, "Receipt.Store");

To be fair, I googled how to add a data binding, so that may not even be correct.

For my button, I have the following code, which didn’t work (I’ve got an instance of my DB open as I code, so I can verify):

private void button3_Click(object sender, EventArgs e)
{
    SqlCommand saveCommand = new SqlCommand("INSERT INTO Receipt (DateCleared, CategoryID, Amount, Store, DateEntered, HaveReceipt) VALUES (@DateCleared, @CategoryID, @Amount, @Store, @DateEntered, @HaveReceipt)");
    saveCommand.Parameters.AddWithValue("@ComboBox", comboBox1.SelectedValue);
    saveCommand.Parameters.Add("@Amount", textBox1.Text);
    saveCommand.Parameters.Add("@DateCleared", dateTimePicker1);
    saveCommand.Parameters.Add("@DateEntered", dateTimePicker2);
    saveCommand.Parameters.Add("@Store", textBox2);
    saveCommand.Parameters.Add("@HaveReceipt", checkBox1);

    this.Dispose();
}

Is this the correct way to go about it? What I am essentially trying to do here is add each value every time the button is clicked; however I fear that this will merely add null values to the rest of the row and create 6 rows each time.

If I need to add code or information let me know. Thanks in advance!

  • 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-05-28T00:11:04+00:00Added an answer on May 28, 2026 at 12:11 am

    Now this is a stab in the dark, because frankly you didn’t post enough info to adequately answer your question in its current form. Ideally it would be nice to have the database schema, but I think I can guess what the types need to be.

    You’re shoving controls (the actual GUI widget) into most of your values. This simply won’t work, the underlying database code has no knowledge of what to do with an object like that. You have to give it the type of data that it’s expecting (varchar fields get strings, datetime fields get DateTime objects, etc). Here’s something that might be closer:

    private void button3_Click(object sender, EventArgs e)
    {
        SqlCommand saveCommand = new SqlCommand(
            "INSERT INTO Receipt (DateCleared, CategoryID, Amount, Store, DateEntered, HaveReceipt) VALUES (@DateCleared, @CategoryID, @Amount, @Store, @DateEntered, @HaveReceipt)");
    
        // Create a parameter, set the database type, and then set the value
        saveCommand.Parameters.Add("@DateCleared", SqlDbType.DateTime);
        saveCommand.Parameters["@DateCleared"] = dateTimePicker1.Value;
    
        // The same
        saveCommand.Parameters.Add("@DateEntered", SqlDbType.DateTime);
        saveCommand.Parameters["@DateEntered"] = dateTimePicker2.Value;
    
        // I'm assuming that this is a string. I could be wrong.
        saveCommand.Parameters.Add("@ComboBox", SqlDbType.VarChar);
        saveCommand.Parameters["@ComboBox"] = (String)comboBox1.SelectedValue;
    
        // I dunno, is this a float? Well now it is.
        saveCommand.Parameters.Add("@Amount", SqlDbType.Float);
        saveCommand.Parameters["@Amount"] = Convert.ToDouble(textBox1.Text);
    
        // Seems like this should be a bool (hopefully)
        saveCommand.Parameters.Add("@HaveReceipt", SqlDbType.Bit);
        saveCommand.Parameters["@HaveReceipt"] = checkBox1.Checked);
    
        // I guess this is a string, but who knows
        saveCommand.Parameters.Add("@Store",  SqlDbType.VarChar);
        saveCommand.Parameters["@Store"] = textBox2.Value;
    
        // No idea why this is here
        this.Dispose();
    }
    

    Obviously with the number of assumptions I’m making, your mileage may vary.

    EDIT

    By the way, you do actually have to execute the SQL when you’re done building it. This just builds the SQL.

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I have a French site that I want to parse, but am running into

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.