0

Hi guys, I am using Visual Studio 2008 and have connected a database correctly as I have done a login that works fine, although when I try to insert information submitted in the text boxes a different table, it doesn't enter after I end program to check it still has no data in. Any ideas? Also I have no idea what is the difference or whether im writing in VB .NET or Visual basic 5...6? lol

Imports System.Data.SqlServerCe
    Public Class frmScrapAVehicle
        Dim con As SqlCeConnection = New SqlCeConnection("Data Source=NESdb.sdf") 'This here, declares where the database is located
        Dim Clear As Double
        Dim myDA As SqlCeDataAdapter
        Dim myDataSet As DataSet
        Dim dt As New DataTable()
        Private Sub frmScrapAVehicle_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            dtpWhen.Value = Date.Today
        End Sub
        Private Sub lnkLogout_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkLogout.LinkClicked
            frmLogin.Show()
            Me.Hide()
        End Sub
    
        Private Sub lnkBack_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkBack.LinkClicked
            frmMain.Show()
            Me.Hide()
        End Sub
    
        Private Sub btnAddVehicle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddVehicle.Click
            If txtFname.Text = "" Then
                MsgBox("Enter a first name.")
            ElseIf txtLname.Text = "" Then
                MsgBox("Enter a last name.")
            ElseIf txtAdd1.Text = "" Then
                MsgBox("Enter an address 1.")
            ElseIf txtTown.Text = "" Then
                MsgBox("Enter a town.")
            ElseIf txtPostCode.Text = "" Then
                MsgBox("Enter a post code.")
            ElseIf txtTelephone.Text = "" And txtMob.Text = "" And txtEmail.Text = "" Then
                MsgBox("Enter a either a telephone number, mobile number or email.")
            ElseIf comboVehicleType.Text = "" Then
                MsgBox("Choose a vehicle type.")
            ElseIf txtReg.Text = "" Then
                MsgBox("Enter the vehicle registration number.")
            ElseIf comboYear.Text = "" Then
                MsgBox("Choose a year.")
            ElseIf comboMake.Text = "" Then
                MsgBox("Choose a manufacturer.")
            ElseIf txtModel.Text = "" Then
                MsgBox("Choose a model.")
            ElseIf chkPrint.Checked = True Then
                PrintScrap.Print()
                'Connect to database'
                con.Open()
                'Attempt to retrieve data'
                Try ' Select username and password that match'
                    Dim cmd As SqlCeDataAdapter = New SqlCeDataAdapter("INSERT INTO ScrapVehicles(Fname, Lname, Add1, Add2, Town, PostCode, Telephone, Mob, Email, VehicleType, RegNo, Year, Make, Model, V5, Collected, CollectionDate)" + "VALUES('" & txtFname.Text & "', '" & txtLname.Text & "', '" & txtAdd1.Text & "', '" & txtAdd2.Text & "', '" & txtTown.Text & "', '" & txtPostCode.Text & "', '" & txtTelephone.Text & "', '" & txtMob.Text & "', '" & txtEmail.Text & "', '" & comboVehicleType.Text & "', '" & txtReg.Text & "', '" & comboYear.Text & "', '" & comboMake.Text & "', '" & txtModel.Text & "', '" & chkV5.Text & "', '" & chkCollected.Text & "', '" & dtpWhen.Text & "')", con)
                    'Catch errors'
                Catch ex As Exception
                End Try
                'Close connection to database'
                If con.State <> ConnectionState.Closed Then
                    con.Close()
                End If
                MsgBox("Vehicle added to your scrap database, and a printed copy is in progress.")
            Else
                'Connect to database'
                con.Open()
                'Attempt to retrieve data'
                Try ' Select username and password that match'
                    Dim cmd As SqlCeDataAdapter = New SqlCeDataAdapter("INSERT INTO ScrapVehicles(Fname, Lname, Add1, Add2, Town, PostCode, Telephone, Mob, Email, VehicleType, RegNo, Year, Make, Model, V5, Collected, CollectionDate)" + "VALUES('" & txtFname.Text & "', '" & txtLname.Text & "', '" & txtAdd1.Text & "', '" & txtAdd2.Text & "', '" & txtTown.Text & "', '" & txtPostCode.Text & "', '" & txtTelephone.Text & "', '" & txtMob.Text & "', '" & txtEmail.Text & "', '" & comboVehicleType.Text & "', '" & txtReg.Text & "', '" & comboYear.Text & "', '" & comboMake.Text & "', '" & txtModel.Text & "', '" & chkV5.Text & "', '" & chkCollected.Text & "', '" & dtpWhen.Text & "')", con)
                    'Catch errors'
                Catch ex As Exception
                End Try
                'Close connection to database'
                If con.State <> ConnectionState.Closed Then
                    con.Close()
                End If
                MsgBox("Vehicle added to your scrap database.")
            End If
        End Sub
    End Class
2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by maj3091
0

Hi,

Does it throw an exception at all?

I'm looking at your SQL query and it looks like your missing a space before the VALUES (maybe I'm reading it wrong - I've just woke up! :) ).

As a simple test, try assigning your SQL query to a string variable and print it to screen and read it back to ensure it looks right.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.