473,396 Members | 1,671 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,396 software developers and data experts.

Trying to Use INSERT INTO in VB.Net but is not INSERTing

Hi, I am using VB.Net in Visual Studio 2008 with a connected SQL Server Compact Database but for some reason I can not get a record to insert into my Database from my Windows Form.

I have used the data connection on the form already to populate a couple of combo boxes but when it comes to commiting the data the sub runs through but there is no additional data in my database.

my code is as follows

Expand|Select|Wrap|Line Numbers
  1.     Private Sub cmdAddQuote_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddQuote.Click
  2.         Dim cnData As New SqlCeConnection 
  3.         Dim cdData As SqlCeCommand
  4.         Dim strsql As String
  5.         strsql = "INSERT INTO HS_QuoteDetail (nbrRecordNbr, nbrItemNbr, nbrItemCount, CurCost) VALUES ('" & Me.txtJobID.Text
  6.         strsql = strsql & "', '" & Me.ItemIDNbr.Text & "', '" & Me.nbrUnits.Text & "', '" & Me.curSubTotal.Text & "');"
  7.         cnData.ConnectionString = "data source = Database1.sdf; Persist Security Info = False"
  8.         If cnData.State = ConnectionState.Closed Then
  9.             cnData.Open()
  10.         End If
  11.         cdData = New SqlCeCommand(strsql, cnData)
  12.         'cdData.ExecuteNonQuery()
  13.         cdData.ExecuteNonQuery()
  14.         MsgBox("Run")
  15.         Me.nbrUnits.Focus.Equals(True)
  16.         cnData.Close()
  17.     End Sub
  18.  
Teh table only contains these 4 fields and another field which is an automatically generated number called nbrQuoteID

All of the fields are number fields but I have tried sending them as text to see if it made a difference (Threw up an error) but it didn't.
Sep 14 '10 #1
5 2276
Why not use a TableAdapter and use the auto-generated insert query?
Sep 14 '10 #2
Ok thanks, I will try and see if I can find anything about that.

I have actually managed to get the data onto the table and to populate a listview to show it is there but when I go back to view the table the records are not there.
Sep 14 '10 #3
Sorry I must be being really thick but I can not for the life of me work out how to INSERT the record, it is asking for five fields yet the first field is an AutoNumber field so I am not sure how to Insert this record.

Expand|Select|Wrap|Line Numbers
  1. Dim taQuote As New HS_fieldDatasetTableAdapters.HS_QuoteDataTableAdapter
  2.         taQuote.Insert(, Me.txtJobID.Text, Me.ItemIDNbr.Text, Me.nbrUnits.Text, Me.curSubTotal.Text)
  3.  
EDIT:

Sorry you will not believe how stupid I have been, I have two tables with similar names and fields and dragged the wrong one.
Sep 15 '10 #4
Sorry back again I have run through the Sub with the Table Adapter and again when I go back to view table data it does not show the updated data again, although the Autonumber keeps going up.
Sep 15 '10 #5
Solved it, It is due to the debug and production Databases being different, A well known issue apparently but not to me. I simply have to copy the database back from Debug to the main folder and teh data is there.
Sep 15 '10 #6

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

Similar topics

7
by: Jared Evans | last post by:
I developed a console application that will continually check a message queue to watch for any incoming data that needs to be inserted into MS SQL database. What would be a low-cost method I...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
2
by: a | last post by:
NEW Post Here's my best guess at how to insert this dataset.... the code runs, but no new records are added to the sql table. I've read and split a delimited text file into a dataset. It...
2
by: altergothen | last post by:
Hi there I am a newbie to ASP.Net - Please Help! I am trying to insert the values of my variables into a database. If I try the following it works perfectly: string insertQuery = "INSERT into...
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
9
by: deja | last post by:
Hi all, For a couple of nights I have been trying to figure something out.. I am trying insert a couple of fields into a database. My url looks something like this; ...
4
bugboy
by: bugboy | last post by:
I'm inserting a new word into table 'w' and a definition into table 'c' which are linked in table 's' which is the relation table for the many to many relationship between 'w' and 'c'. I've been...
2
by: jthep | last post by:
How can I use bulk insert to insert a text file where the columns in the text file is in different order than the columns in the table? I have a ZIP table with Zip_Code, Zip_City, Zip_State and...
5
by: =?Utf-8?B?bXBhaW5l?= | last post by:
Hello, I am completely lost as to why I can't update a DropDownList inside a DetailsView after I perform an insert into an object datasource. I tried to simply it down to the core demostration:...
2
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
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...
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,...

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.