Jump to content

Visual Basic .net help please


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...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.