Jump to content

Recommended Posts

Hi, im making a project in visual basic, i am making a order form for items.

 

all i want is to type the catologue number in 1 textbox and then it display the name of the item in another textbox.

 

Code:

Imports System.Data.OleDb

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox2.Enabled = False

        
    End Sub

    Private Sub CheckBox1_Checked(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked Then
            TextBox2.Enabled = True
        End If
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Dim ConnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=../../../../../Shop.mdb;User Id=;Password=;"

        Dim oConn As New OleDbConnection(ConnStr)

        oConn.Open()

        Dim r1, r2 As OleDb.OleDbCommand

        r1 = New OleDb.OleDbCommand("SELECT Catologue Number FROM Stock WHERE Catologue Number = '" & TextBox1.Text & "'", oConn)
        r2 = New OleDb.OleDbCommand("SELECT Name FROM Stock WHERE Catologue Number = '" & TextBox1.Text & "'", oConn).ToString

        If r1.ExecuteScalar.ToString <> TextBox1.Text Then
Else
TextBox3.Text = r2.ExecuteScalar.ToString
End If
oConn.Close()
    End Sub
End Class

 

Error:

"Syntax error (missing operator) in query expression 'Catologue Number'."

 

can anyone help?

 

im sooo confused ???

Link to comment
https://forums.phpfreaks.com/topic/116086-visual-basic-net-help-please/
Share on other sites

This is an sql problem, nothing to do with vb.net.

 

Field names should not contain spaces, however if you insist on using spaces I believe you can use [] brackets to enclose the field name (this only applies to access and other MS database types).

 

eg;

 

"SELECT [Catologue Number] FROM Stock WHERE [Catologue Number] = '" & TextBox1.Text & "'"

 

 

This is an sql problem, nothing to do with vb.net.

 

Field names should not contain spaces, however if you insist on using spaces I believe you can use [] brackets to enclose the field name (this only applies to access and other MS database types).

 

eg;

 

"SELECT [Catologue Number] FROM Stock WHERE [Catologue Number] = '" & TextBox1.Text & "'"

 

thanks, but i now have an error:

"Object reference not set to an instance of an object."

 

  • 1 year later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.