Click here to Skip to main content
15,886,693 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to save 5 textboxs 1 combo and datetimepicker to a database but the only thing saved is the datetimepicker. I am very confused with this and dont see why this code isn't working any suggestions much appreciated.

private void btn_Save_Click(object sender, EventArgs e)
        {     
            
                if (lbl_LibId.Text == "*")
            {
                string sql = "insert into Request (Date, Part_Number, Request_By, Assigned_CC, IC_Analyst, Priority, Comments)" +

                             " values(@Date, @Part_Number, @Request_By, @Assigned_CC, @IC_Analyst, @Priority, @Comments)";

                Request.ExecuteSQL(sql, new[] {

                        new SQLiteParameter("@Date", dateTimePicker1.Text),
                        new SQLiteParameter("@Part_Number", txt_Part_Number.Text),
                        new SQLiteParameter("@Request_By", txt_Count_Request_By.Text),
                        new SQLiteParameter("@Assigned_CC", txt_Assigned_Code.Text),
                        new SQLiteParameter("@IC_Analyst", txt_Analyst.Text),
                        new SQLiteParameter("@Priority", cb_Priority.Text),                       
                        new SQLiteParameter("@Comments", txt_Comments.Text),                         
                        
                    });
                

                DataBind();
                
            }
        }


What I have tried:

code similar has worked in the past I am at a lost.
Posted
Updated 8-Oct-21 5:50am

We can't tell: we don't have access to your database or your code while it is running.

If the DTP value is being inserted, then all the value are - so either every other control is empty, or that code isn't being executed at all. And we can't help you find out which.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 
Comments
Member 12349103 8-Oct-21 12:11pm    
In debug I see the Date value the other values are "". The database is all text.
OriginalGriff 8-Oct-21 12:42pm    
Then that's why only the date gets stored - the others do, but they are empty.
Now you need to track back to find out why - and we can;'t do that for you eitehr as we can't even see your screen!

And ... tell me you aren't saving everything in your DB as text? Because if you are, that's a very big mistake, and it is going to come back and bite your ass, and bit it hard. Change it now, before it become a real problem ... or you are have to have loads of trouble and pain in the near future.
Please tell me you're not saving DateTime values as strings in the database...

Without knowing the structure (datatypes of the columns) of the table you're trying to save to, it's impossible for anyone to tell you what's going on.

But, I'll tell you this. The constructor of the SqlParameter class you're using will treat every piece of information you're passing to them as strings, since that is what you're passing to every instance of SqlParameter.

What does that mean? Well, if a column in your table is an INT or other non-VARCHAR type, you're attempting to to put a string into a column that cannot hold it.

"100" and 100 are NOT the same value type! One is a string, and the other is an integer. Chances are pretty good you're trying to save "100" (a string) in a column with a type of INT. That's not going to work.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900