469,097 Members | 1,613 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,097 developers. It's quick & easy.

the last record cannot be deleted

hello every body
when iam trying to delete the last record in DGV this erro appears
"Input string was not in a correct format."
this error appears only when i am trying to delete the last record.
.
the code i using is the following
Expand|Select|Wrap|Line Numbers
  1. public void Delete(int id)
  2.         {
  3.             ////////////Delete the record from the dataset.///////////
  4.             DataRow[] DR = dttel.Select("id=" + id + "");
  5.             DR[0].Delete();
  6.         }
  7.  
  8.  
  9.  
  10.  
  11.         public void UpdateTelephone(
  12.             int id,
  13.          string name,
  14.          string title,
  15.          string home_phone,
  16.          string mobile_phone,
  17.          string address,
  18.          string notes)
  19.  
  20.         {
  21.             //Insert a new record in the Databse.
  22.             string Insert_Str = "insert into tel( " +
  23.             "name," +
  24.             "title," +
  25.             "home_phone," +
  26.             "mobile_phone," +
  27.             "address,notes)" +
  28.             " values ("+
  29.             " '"+name+"'         ,"+
  30.             " '"+title+"'        ,"+
  31.             " '"+home_phone+"'   ,"+
  32.             " '"+mobile_phone+"' ,"+
  33.             " '"+address+"'      ,"+
  34.             " '"+notes+"'        )";
  35.             //////////////Update a new record in the Database.
  36.             string Update_str = "update  tel set " +
  37.                         "name='"+name+"'," +
  38.                         "title='"+title+"'," +
  39.                         "home_phone='"+home_phone+"',"+
  40.                         "mobile_phone='"+mobile_phone+"'," +
  41.                         "address='"+address+"'," +
  42.                         "notes='"+notes+"'"+
  43.                         "where id="+id+" ";
  44.             ////////////Delete the record from the Database.
  45.             string Delete_str = "delete from tel where id= " + id + " ";
  46.             ////////////////defining sqlcommands////////////////////
  47.             OleDbCommand Insert_Cmd = new OleDbCommand(Insert_Str, MyConnection.connect());
  48.             OleDbCommand Update_cmd = new OleDbCommand(Update_str, MyConnection.connect());
  49.             OleDbCommand Delete_cmd = new OleDbCommand(Delete_str, MyConnection.connect());
  50.             ////////////////Defining the adapter command////////////
  51.             DA.InsertCommand = Insert_Cmd;
  52.             DA.UpdateCommand = Update_cmd;
  53.             DA.DeleteCommand = Delete_cmd;
  54.             ////////////////update the datasource.///////////////////////
  55.             try
  56.              {
  57.                DA.Update(dttel);
  58.              }
  59.              catch (OleDbException ex)
  60.             {
  61.                 MessageBox.Show("Warning" + ex.Message,
  62.                 "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  63.             }
  64.         }

can any body help me.
Jan 25 '08 #1
2 1047
leoiser
41
it seems something wrong with your query.Make sure your query is running fine...may be single quotes in one of the values may cause the problem

for example if you put address as leoiser's home in that single quotes will break the query,so replace everything with replace single quotes to two single quotes..

Expand|Select|Wrap|Line Numbers
  1. address.Replace("'","''");
Thanks
Jan 29 '08 #2
Shashi Sadasivan
1,435 Expert 1GB
Could you please tell which line is causing that exception!

Along with the string that was generated (can be picjked up from debug mode)
Jan 29 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Alistair | last post: by
4 posts views Thread by Susan Bricker | last post: by
20 posts views Thread by Bryan | last post: by
5 posts views Thread by prakashwadhwani | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by kglaser89 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.