473,786 Members | 2,380 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

the last record cannot be deleted

2 New Member
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 1252
leoiser
41 New Member
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 Recognized Expert Top Contributor
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

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

Similar topics

5
1547
by: Alistair | last post by:
hi peoples and masterful gurus (a little bit of grovelling never hurt anyone...apart from the sore knees) I'm after a little bit of advice on how to do something. basically a history of the last 10 pages viewed or the id of the last 10 visitors to a page, but how do I make this "rolling" e.g. a visitor looks at a page, his id is stored in an access 2000 db, another vsitor then looks at the page, his id is also stored, when I get to
3
1548
by: Prakash | last post by:
Below is my code to delete a record in a continuous form. I can't figure out any reason but sometimes (another) record gets deleted instead of where the record pointer is positioned. Small table - just 750 records ... no primary key defined. Using Access 2003 under WinXP SP1. There must be something I've overlooked. Maybe one of you gurus could help.
4
7851
by: Susan Bricker | last post by:
I have a command button on a form that is supposed to Delete the record being displayed. The record is displayed one to a form. The form is not a Pop-Up nor is it Modal. Tracing the btnDelete event routine shows that AllowDeletions is TRUE. When the Delete button is clicked (without TRACE ON), I get a 'beep', the recordselector (vertical bar on left of form) gets dark in color, but the record is not deleted. Also, there is no error...
20
2149
by: Bryan | last post by:
hello all... im trying to add a record to an sql db on ms sql server 2000, using vb.net. seems to be working.. except for one thing, one of the columns in the database is a bit datatype, and though i get no syntax errors when compiling, i get an error indicated that the data would be truncated. the field is login_status. ive tried in quotes and not, giving it an integer variable with the number 1
10
4404
by: A_PK | last post by:
I am writing mobile application using Vb.net when i click the last row of list view, and try to delete it.... will promtpy the following message "Additional information: ArgumentOutOfRangeException" what does that mean ? I can delete any row without problem but except last row only....
17
2529
by: michel.ank | last post by:
Hi, I'm using the class PrintLines and my last record of page aren't with the borders. Somebody can help me? Thanks,
5
3186
by: prakashwadhwani | last post by:
The Delete Event/Proc & "Save_Fields_In_Form_Header" Event/Proc in my form were working perfectly. However, after I added a call to the "Save_Fields_In_Form_Header" Event/Proc in the "Current" Event of my form, and I now try to Delete a record, I get ... Run-Time Error 3218 - Could not Update; Currently Locked. My Access application then effectively freezes forcing me to shut Access down & re-start. The record DOES get deleted...
10
7173
beacon
by: beacon | last post by:
Hi everybody, This is probably going to sound unorthodox, but I have to log records that are deleted...I know, go figure. Anyway, I have a form with a (continuous) subform, and on the subform I have a command button, called cmdDelete, that launches a dialog form, called frmDeleteCurrentRecord, where the user has to enter their name and a reason. I have managed, through a ton of trial and tribulation, found a way to delete the current...
6
3812
BeemerBiker
by: BeemerBiker | last post by:
I can't get rid of a "deleted" record in a database. Even if I delete it the record shows back up the next time I do an update. The following code generates an error message when using "driver=microsoft access driver (*.mdb)" Either in the app QTADO or in my own perl script that uses dbi:ODBC really simple command: "UPDATE mytable SET Field1='rec'; error message: "The Microsoft Jet database engine stopped the process because you and...
0
9492
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10360
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10108
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9960
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4064
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.