473,785 Members | 2,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Specified Cast Invalid on MS Access database!

2 New Member
I've read through numerous postings by other users here but was not able to find the solution to my issue. It's probably a simple one, but it's racking me at this point.

I have two databases in MS Access with a table "Affiliatio n". Both contain four columns/fields. I am writing an application to pull some data from Table1's affiliation table and inserting it into Table2's affiliation table. The datatypes are all the same for all four fields in both tables, but for some reason I get an error "specified cast is invalid" on my final field. Here is the code I'm using:

Expand|Select|Wrap|Line Numbers
  1.  while(CMDReader.Read())
  2.     {    
  3. SQL_Command2 = "INSERT INTO tblAffiliation(AffiliationID, [Short], [Long], Affiliation) VALUES(" + CMDReader.GetInt32(0) + ",'" + CMDReader.GetString(1) +"', '" + CMDReader.GetString(2) + "', " + CMDReader.GetInt32(3) + ")";
  4.  
  5. OleDbCommand InsertCMD = new OleDbCommand(SQL_Command2, FAC_Data);
  6.  
  7. InsertCMD.ExecuteNonQuery();
  8.  
  9.     }
on the "CMDReader.GetI nt32(3)" is where the casting error occurs. It's datatype is an Integer in the MS Access table. The first "CMDReader.GetI nt32(0)" works fine, so I don't understand why this one doesn't. The only difference is that the "0" is a long integer datatype in the table and the "3" is simply an integer.

Any thoughts?
Sep 4 '07 #1
1 1396
one320b
2 New Member
Actually - nevermind, I just switched it and didn't do any conversions, etc.

I just switch the method from GetInt32(3) which wasn't working to simply GetValue(3) and all is fine now. It may not be the best method - but this application is not exactly labor or memory intensive so no big deal.
Sep 4 '07 #2

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

Similar topics

7
24847
by: VPaul | last post by:
I hope I am posting to the correct group for assistance. Please advise me if there is another group I should go to. I am new to this, so I apologize if I don't explain this very well. I do need some help. Thanks in advance. I am trying to bring data in to a Visual Foxpro application from an AS/400. I have the Client Access ODBC driver loaded on a PC running WinXP. The SQL query I have made works fine, except it is really slow to...
3
10519
by: PK9 | last post by:
I am looking for assistance in pinpointing the cause of the following exception. I am getting a "Specified Cast is not valid" exception on my page. I am trying to populate a datagrid. One of my columns is a template column where I'd like to evaluate the data brought back from the db and populate the column with a "Y" or "N" depending on the value in the db. Here is the code that is causing it as well as the error (below). ERROR...
6
6424
by: Biva | last post by:
Hello All, Please help. I get the following error from my webpage: System.InvalidCastException: Specified cast is not valid. at Time.MaintAtRiskProjects.UpdateProject(String Project, String AtRiskCode, String Comment) Code for UpdateProject(String Project, String AtRiskCode, String Comment) is:
2
3093
by: Fabian | last post by:
Hi, I work with asp.net 2.0 and I have a intermittent error, only happens a few times a day. In the page I evaluate a Query String and then I get data form a database. The code snipped: try {
3
1699
by: Mike Cooper | last post by:
Hello All! I am getting teh above error message on the following code: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim dgt As DataGridTableStyle = Main_DataGrid.TableStyles(0) Dim cm As CurrencyManager = CType(Me.BindingContext _
2
1627
by: James | last post by:
I'm a newbie to vb.net, and classes were something I never played with in "standard" vb, but... Basically,part of my program comprises of some tcp/ip stuff, and I used the following code to start off the connection: Public Sub Main() Const PortNumber As Integer = 8022 Dim tcpListener As New TcpListener(PortNumber) tcpListener.Start()
0
1392
by: df | last post by:
I'm seeing a strange problem in the Web App config tool: After creating a role and a user, going back to the Security tab home page, I get a "Specified cast is not valid" error. I've set up my web application to use SQL Server to store the Membership database using aspnet_regsql.exe and have successfully opened the Web Config Tool. Then, I create a role, and go look in the SQL Server aspnet_roles table, and there is the role. All...
2
3532
by: Kashiefah | last post by:
Hi, I keep on receiving this error when I click on the edit email link from the datagrid:Specified cast is not valid. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Specified cast is not valid. Source Error: Line 44: while...
27
2926
by: arial | last post by:
Hi I am new to programming. learning c# , asp.net. write a simple program: to get the id from database and save it to arraylist to find the max(id). and getting exception: Specified cast is invalid. at line: int low = (int)arrm;
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10329
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...
0
10152
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10092
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,...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
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
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
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

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.