Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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");
Posted
Updated 29-Sep-12 23:47pm
v12
Comments
Anele Ngqandu 25-Sep-12 7:43am    
What part of the code do you getthat error? Please put a break point then youl see wher things go wrng. A value is expecting to get a decimal not a string value somewher
mhassan083 26-Sep-12 0:43am    
error gets when run and does not refer to any code
Oshtri Deka 26-Sep-12 3:43am    
//in ms access datatype: autonumber
oda.UpdateCommand.Parameters.Add("@sn_s", OleDbType.Integer).Value = textboxFirstname.Text;

The last part looks suspicious - textboxFirstname for identity value?!
Or you tend to give strange names to your variables.
mhassan083 26-Sep-12 6:29am    
textboxFirstname is the name of text only ,just name

Are you sure that the textboxes contain the data you expect them to contain?
For example, oda.UpdateCommand.Parameters.Add("@sn_s", OleDbType.Integer).Value = textboxFirstname.Text; looks very strange - is First Name an Integer?
Furthermore, do some parsing for the numerical types from the strings. If you need an integer, use e.g. int.Parse(textbox10.Text); for a decimal, decimal.Parse(textbox11.Text)
 
Share this answer
 
Comments
mhassan083 26-Sep-12 1:33am    
yes i'm sure ,textboxfirstname.text is display sn_s with type autonumber in access and integer here.
Quote:
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/Account.mdb");

con.Open();
OleDbCommand cmd = new OleDbCommand("update payment set Type_Name='" + textBox2.Text + "',Amount='" + textBox3.Text + "',Paid_Date='" + textBox4.Text + "',Paid_By='" + textBox5.Text + "',Received_By='" + textBox6.Text + "' where id=" + pid + "", con);
cmd.ExecuteNonQuery();
MessageBox.Show("Information updated successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
con.close();



use this code for update ur value..

Regard
Sham
:)
 
Share this answer
 
Comments
mhassan083 26-Sep-12 2:54am    
what (pid) do you mean ??textbox or what?!
Shambhoo kumar 26-Sep-12 3:12am    
same as sn_s
mhassan083 26-Sep-12 3:27am    
what is the textbox display it if id=pid pid??!!like Received_BY= textBox6.Text
also after run give me error (error in update syntax)
Shambhoo kumar 27-Sep-12 2:05am    
u right this code like Received_BY= '"+textBox6.Text+"'
Hi try with proper conversion as below

oda.UpdateCommand.Parameters.Add("@amount_ paid", OleDbType.Currency).Value = Convert.toDecimal(textBox3.Text); // for currency


oda.UpdateCommand.Parameters.Add("@date_record", OleDbType.Date).Value =Convert.ToDataTime(textBox5.Text); //Date


oda.UpdateCommand.Parameters.Add("@sn_s", OleDbType.Integer).Value = Convert.ToInt( textboxFirstname.Text); //for integer
 
Share this answer
 
 
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