Click here to Skip to main content
15,892,768 members

error : input string is incorrect format !! How to solve this error?

mhassan083 asked:

Open original thread
Hii everyone,


i'm beginner. After many tries error is still exist (error : input string is incorrect format !! How to solve this error??)

this is my code :
C#
int x;
        string conString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=..\\..\\org.accdb";
        OleDbConnection con = new OleDbConnection(conString);
        DataTable dt = new DataTable();
        OleDbDataAdapter oda = new OleDbDataAdapter();
        oda.UpdateCommand = new OleDbCommand("update student set id_civil_st=@id_civil_st,names=@names,phone=@phone,address=@address,school_ year=@school_ year,amount_ paid=@amount_ paid,amount_rest=@amount_rest,date_record=@date_record,date_start=@date_start,date_end=@date_end where sn_s=@sn_s", con);
        //in ms access text
        oda.UpdateCommand.Parameters.Add("@id_civil_st", OleDbType.Char).Value = id_civil_st.Text;

        //in ms access datatype : text
        oda.UpdateCommand.Parameters.Add("@names", OleDbType.Char).Value = names.Text;
        //in ms access datatype: text
        oda.UpdateCommand.Parameters.Add("@phone", OleDbType.Char).Value = phone.Text;
        //in ms access datatype: text
        oda.UpdateCommand.Parameters.Add("@address", OleDbType.Char).Value = address.Text;
        //in ms access datatype: text
        oda.UpdateCommand.Parameters.Add("@school_ year", OleDbType.Char).Value = textBox2.Text;
        //in ms access datatype: currency
        oda.UpdateCommand.Parameters.Add("@amount_ paid", OleDbType.Currency).Value =Convert.ToDecimal( textBox3.Text);
        //in ms access datatype currency
        oda.UpdateCommand.Parameters.Add("@amount_rest", OleDbType.Currency).Value =Convert.ToDecimal( textBox4.Text);
        //in ms access dat/time
        oda.UpdateCommand.Parameters.Add("@date_record", OleDbType.Date).Value =Convert.ToDateTime( textBox5.Text);
        //in ms access date/time
        oda.UpdateCommand.Parameters.Add("@date_start", OleDbType.Date).Value =Convert.ToDateTime( textBox6.Text);
        //in ms access date/time
        oda.UpdateCommand.Parameters.Add("@date_end", OleDbType.Date).Value =Convert.ToDateTime( textBox7.Text);
        //in ms access datatype: autonumber
        oda.UpdateCommand.Parameters.Add("@sn_s", OleDbType.Integer).Value =Convert .ToInt32( sn_s.Text);


        con.Open();
        x = oda.UpdateCommand.ExecuteNonQuery();
        con.Close();
        if (x >= 1)
            MessageBox.Show("Records has been updated");
Tags: C# (C# 4.0), ADO.NET, Microsoft Access

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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