Insert current date in a field

Asked

Viewed 363 times

3

I’m using dataAdapters do . Net to create a project as a BD learning base with C#. I chose an easier path that would be to work most of the time in design mode through the Datasets. The battle I face is to insert the current date into a BD field. The following code works well with strings for the text and int for foreign key fields:

orcTableAdapter.Insert(Int32.Parse(comboBox2.ValueMember),datatime.Now, 0,Int32.Parse(comboBox1.ValueMember));
orcTableAdapter.Update(vorc2DataSet.Orcamento);
vorc2DataSet.AcceptChanges();
orcTableAdapter.Fill(vorc2DataSet.Orcamento);

I know there are ways to convert through Add.Parameters but I don’t know how to adapt to this format without having to change all the code.

Follow the exception message:

An unhandled Exception of type System.Formatexception occurred in mscorlib.dll

Additional information: The input character string was not in a correct format.

  • Some things there indicate that you’re not learning the right way, especially if you’re worried about changing code if that’s necessary. But in this particular case these combobox must contain incompatible data to generate an integer. I cannot guarantee with so little information. While reading about this: http://answall.com/q/101691/101. Your problem doesn’t seem to be with Visual Studio.

  • Something tells me you haven’t read my question carefully either. The data of the combobox works perfectly, what does not work is my attempt to enter the date and time directly in the BD through the standard command for Visual Studio Forms (Datetime.Now). I’ve been trying to solve this detail for over 8 hours and all this time I’ve spent with reading. I still get there.

1 answer

2


The only method used in this section that produces this exception is the Int32.Parse(), then the problem certainly lies in the contents of the variables of comboboxes existing. What you have in them should be possible to convert to an integer.

I advise avoiding the use of obsolete technologies such as TableAdapter and Access.

  • Friend, you were right about Int32.Parse, but my biggest mistake was that when looking for an error on the date, I ended up changing the place date field in the access and Wizard of the source data was in reverse order. Here is the corrected code for clarification: orcTableAdapter.Insert(Convert.Toint32(comboBox2.Selectedvalue), Datetime.Now,Convert.Toint32(comboBox1.Selectedvalue),0); orcTableAdapter.Update(vorc2DataSet.Budget); vorc2DataSet.Acceptchanges(); orcTableAdapter.Fill(vorc2DataSet.Budget);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.