473,811 Members | 2,856 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

issue with the insert sql command using vb.net

momotaro
357 Contributor
Hi,

Am trying to connect and insert a record into my database using vb.net this is my code:
Expand|Select|Wrap|Line Numbers
  1. cs = New SqlConnection("Data Source=AYACHMOHAMED;Initial Catalog=Employe;Integrated Security=True")
  2.  
  3.         cs.Open()
  4.         sqlcom = New SqlCommand("INSERT INTO EMPLOYE VALUES 3, 'AYACH', 'PDG'", cs)
  5.         Try
  6.             ra = sqlcom.ExecuteNonQuery()
  7.         Catch ex As Exception
  8.             MsgBox("wrong " & ra)
  9.         End Try
  10.         cs.Close()
the problem is ra = 0 mean no insertion made I can't figure it out!

thank's in advance
Jan 11 '11 #1
7 1919
Rabbit
12,516 Recognized Expert Moderator MVP
Your insert syntax is incorrect.
Jan 11 '11 #2
momotaro
357 Contributor
OK how about this one:
Expand|Select|Wrap|Line Numbers
  1. sqlcom = New SqlCommand("INSERT INTO EMPLOYE (field1, field2...) VALUES (value1, value2, ...)", cs)
guess what doesn't work either
Jan 11 '11 #3
Rabbit
12,516 Recognized Expert Moderator MVP
Assuming that your table is actually named EMPLOYE and not EMPLOYEE. And assuming your connection string cs is correctly formatted. And assuming your data source AYACHMOHAMED is properly set up.

If that really is the entire SQL string you tried to use, then that is also incorrect.

Expand|Select|Wrap|Line Numbers
  1. sqlcom = New SqlCommand("INSERT INTO EMPLOYE (ActualFieldNameOfIntegerField, ActualFieldNameOfStringField, ActualFieldNameOfOtherStringField) VALUES (3, 'AYACH', 'PDG')", cs)
Jan 11 '11 #4
momotaro
357 Contributor
concerning the EMPLOYE is the french version of EMPLOYEE for the rest all of it is ok and guess what I know that there is something wrong with it and this is why I posted the question are you realy trying to help here or just piling up your postes...?
Jan 11 '11 #5
Rabbit
12,516 Recognized Expert Moderator MVP
I'm trying to help but if you really used
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO EMPLOYE (field1, field2...) VALUES (value1, value2, ...)
as your SQL string, of course it's going to fail. You didn't specify the field names or the values to use. You basically copied and pasted the syntax from a SQL help file.

So either, A) that is not the actual SQL string you used in your code, in which case we can't help you without seeing the actual string you used or B) that is the actual string you used.

If B, then you either didn't read the rest of the help file or you didn't understand it. So, assuming you did read it, but the text was confusing, I gave you the correct SQL string to use from the minimal information that was provided.

Which was
Expand|Select|Wrap|Line Numbers
  1. sqlcom = New SqlCommand("INSERT INTO EMPLOYE (ActualFieldNameOfIntegerField, ActualFieldNameOfStringField, ActualFieldNameOfOtherStringField) VALUES (3, 'AYACH', 'PDG')", cs)
All you had to do was replace some of what I had with your field names. However, judging by your most recent post, you did not try my suggestion.
Jan 11 '11 #6
momotaro
357 Contributor
you didn't even remember my first post you are such a lost cause...! it's realy pitty there was a time when we realy havn't to argue about things like these and when people were realy truly engaged on this site...
thx anyway
Jan 11 '11 #7
Rabbit
12,516 Recognized Expert Moderator MVP
Your first post had no field names and your first post had incorrect SQL syntax. You looked up the correct syntax, but you didn't replace the values in the syntax with the values that were relevant to your tables. So you ended up with incorrect syntax again. So I gave you the correct syntax in which all you had to to was plug in your field names. But you didn't do that. At no point did you give me all the relevant information that is needed for syntactically correct SQL. Nor did you give the impression that you even tried.
Jan 11 '11 #8

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

Similar topics

2
13401
by: george | last post by:
This is like the bug from hell. It is kind of hard to explain, so please bear with me. Background Info: SQL Server 7.0, on an NT box, Active Server pages with Javascript, using ADO objects. I'm inserting simple records into a table. But one insert command is placing 2 or 3 records into the table. The 'extra' records, have the same data as the previous insert incident, (except for the timestamp).
1
12884
by: Mike | last post by:
I am trying to use the 'Bulk Insert' command to load a data file into a MS-SQL db. The line I am using is: Bulk Insert SVC_Details From "C:\XFILE.TXT" With (FieldTerminator = ',') I have tried the file name with " around it and with ' around it and both the " and ', but every time the Query Analyzer comes back with the following error: ---Begin Error Msg---
3
37818
by: Ed | last post by:
Hi, I want to load data to a table in Sql Server from a dataset table in my vb.net app using a dataAdapter. I know how to do this as follows (my question is to see if I can reduce the amount of code below): .... Dim DA As SqlDataAdapter = New SqlDataAdapter Dim Parm As New SqlParameter ....
0
1498
by: Rob Dob | last post by:
How do I create a insert command that will take a datatable or datarow as a parameter instead of me having to supply it with parameters for each field value. I heard something about using the v2.0 SqlHelper class (MS Data Application Block), however I don't have a clue how to use this and wondering if using it would be more work then entering in the 50 fields. Am I better off just modifying the insert command that was created...
5
4835
by: mabond | last post by:
Hi VB.NET 2005 Express edition Microsoft Access 2000 (SP-3) Having trouble writing an "insert into" command for a Microsoft table I'm accessing through oledb. I've tried to follow the same principle I'd use if it was an sql database but I'm getting an error telling me the syntax of the "insert into" command
1
3648
by: Iwan Petrow | last post by:
Hi, I do this - take some data with sqldataadaptor (at this moment 2000rows) in fill datatable. For each two rows do some calculations and save data to the database with insert command. (the data which I insert are 5 int values for each two rows - so 2000*1999 insert commands) In this way it is very slow. I think this is because of the invoking so
3
4709
by: iKiLL | last post by:
Hi all I am having problems getting my SqlCeDataAdapter to Update the SQL Mobile Data base. i am using C# CF2. I have tried this a number of different ways. Starting with the command builder but eventually i wrote out the entire command my self, and still nothing. The only thing that i can think this that because i am trying to add a table that is created outside the data adaptor and then Merge/Copy the data into
3
11228
by: Randy | last post by:
I think that this is a really simple question. I have a table adapter set up with the various sql queries. I'd like to allow the user to make changes to a given row on a form. Each of the changes is made using textboxes (not a data grid). Once done, they click a Save button, which should call the insert query on the tableadapter. I can't seem to figure out how to call this. I could do it using a data adapter, but there are many...
1
3451
by: Freedolen | last post by:
Hi, I have checked with some sample data and found inserting of data using 'insert command' takes more time than using 'load data' command to load data from another file. What is the process difference between these two commands. I have another question, when i insert data using load data command from external file is there anyway to get how much rows inserted at the time of loading the data. Regards, Freedolen
1
1667
by: Lawrence Pereira | last post by:
Can any one help me in inserting any date into the table using insert command because when i m trying to insert date using insert command the query executes but the date is totally wrong if i am inserting 6/29/1982 as date the output i get is 1900-01-01 00:00:00.000; and if i change it to 06- 29-1982 then the output comes right, I want to insert date using a gui application so what should be the format,,,,,,
0
9722
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
9603
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
10644
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
10379
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...
0
10124
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
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4334
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
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
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.