473,473 Members | 2,219 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Database Update Problem

1 New Member
Hello I'm developing a page that will submit records into multiple tables. But I'm having issues with the primary key. Here ismy Code:

Expand|Select|Wrap|Line Numbers
  1. private void addRef_Click(object sender, System.EventArgs e)
  2.         {
  3.             connection = new SqlConnection("user id=iwireless;data source=10.50.1.10;password=ipnxiwireless;initial catalog=ipNX_Telecoms");
  4.             candCommand = new SqlCommand("insert into candidate(FName,Surname,OName,Address,Sex,DoB,SoOrigin,Nationality,Tel_1,Tel_2,Email)values('fname','sname','oname','address','gender','DoB','soo','nationality','mphone','ophone','email')",connection);
  5.             pryKeyCommand = new SqlCommand("select ID from candidate where FName ='Fname' AND Surname ='sname'",connection);
  6.             refCommand = new SqlCommand("insert into refTable(ID,refName,refAddress,refNo,refEmail)values('ID','rName','rAdd','rNo','rEmail')",connection);
  7.             refCommand = new SqlCommand("insert into refTable(ID,refName,refAddress,refNo,refEmail)values('ID','rName_2','rAdd_2','rNo_2','rEmail_2')",connection);
  8.             candAdap = new SqlDataAdapter(candCommand);
  9.             pryKeyAdap = new SqlDataAdapter(pryKeyCommand);
  10.             refAdap = new SqlDataAdapter(refCommand);
  11.             connection.Open();
  12.             candCommand.ExecuteNonQuery();
  13.             pryKeyCommand.ExecuteNonQuery();
  14.             refCommand.ExecuteNonQuery();
  15.             Response.Write("Ok");
  16.         }
]
here is the error I get:

Syntax error converting the varchar value 'ID' to a column of data type int.
Jun 7 '07 #1
2 1000
Frinavale
9,735 Recognized Expert Moderator Expert
Hi Anselm Patrick,
Welcome to TDSN!
Please refrain from posting your question in reply to another question (start a new discussion for your question). Also please post your questions in the Forums->.NET area. Thanks.

As for your question, it appears that on line 6 you are supplying 'ID' (which is a string value) when you should be supplying a numeric value.

-Frinny
Jun 7 '07 #2
nateraaaa
663 Recognized Expert Contributor
You apparently have a data type mismatch on ID. It seems that the error message is saying that you are passing a varchar instead of an int. You will either need to convert the varchar to an int using Convert.ToInt32(ID) or change the datatype for the ID column on your table. Give one of these a try and let us know if this fixes your problem.

Nathan
Jun 7 '07 #3

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

Similar topics

1
by: Darn | last post by:
Hi all How do i solve this problem. I'm web developer from Malaysia, the problem occurs when i ftp an Access database which i'm using for this particular web site for it's database.The form...
7
by: PC Datasheet | last post by:
Looking for suggestions ---- A database was designed for a national automobile inspection program. In it's simplest form, the database has two tables: TblOwner OwnerID <Year/Make/Model owned...
3
by: Tc | last post by:
Hi, I was curious, I am thinking of writing an application that loads a dataset from a database that resides on a server. The question I have is this, if multiple copies of the app will be...
7
by: Zachary Hilbun | last post by:
The below is some test code to help me learn how to update a dataset. It is supposed to read the value of UserCounter and write it back. The UserCounter is being read correctly as 0, is 1 when...
1
by: needin4mation | last post by:
Hi, I am uploading a file and changing a record in a database. When the database is updated, I retrieve the last_insert_id() to get the latest row key. I also have a Page_Load event that...
2
by: TJ | last post by:
Hi All, I am having some trouble. I have created a database via the new database option inside VWD2005. Then and table or two. I have been able to perform INSERT and SELECT operations on...
16
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record...
2
by: pascal.baetscher | last post by:
Hello everyone, I face currently a problem where I could need some input for searching the source of the Problem System: SQL Server 9.0 I fill from Database A with triggers Database B,...
6
by: Tark Siala | last post by:
hi i'm using VS.NET 2005 +SP1 C#, and i connect access database by ADO.NET 2.0. i'm using Dataset to (insert,update,delete) and in get data i use (Datareader), but my problem when i do this: 1 -...
30
by: fniles | last post by:
On my machine in the office I change the computer setting to English (UK) so the date format is dd/mm/yyyy instead of mm/dd/yyyy for US. This problem happens in either Access or SQL Server. In the...
0
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,...
0
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...
0
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.