473,383 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

issue with the insert sql command using vb.net

momotaro
357 100+
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

✓ answered by Rabbit

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)

7 1907
Rabbit
12,516 Expert Mod 8TB
Your insert syntax is incorrect.
Jan 11 '11 #2
momotaro
357 100+
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 Expert Mod 8TB
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 100+
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 Expert Mod 8TB
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 100+
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 Expert Mod 8TB
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
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. ...
1
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...
3
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...
0
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...
5
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...
1
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...
3
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...
3
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...
1
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...
1
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.