|
-
Jul 31st, 2010, 11:50 AM
#1
Thread Starter
New Member
[RESOLVED] Syntax error in FROM clause.
I am brand new to programming I'm trying to finish my last programing assignment for the semester and have hit a wall. I'm suppose to create a database that list a countries name, that countries currency type, and the conversion rate from 1 USD to a selected currency type.
I'm using VB 2010
the connection method I'm using is Microsoft Access Database File (OLE DB)
here is my code i have high lighted the part of code in red that is giving me the problem and entered my question in green text at the point i keep getting the error.
Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click
'access and stores the database
Dim strSql As String = "Select * FROM Currency"
Dim strPath As String = "Provider=Microsoft.Ace.OLEDB.12.0 ;" _
& "Data Source=C:\Users\Per\Documents\Currency.accdb"
Dim odaCurrency As New OleDb.OleDbDataAdapter(strSql, strPath)
Dim datCurrency As New DataTable
odaCurrency.Fill(datCurrency) This is where i keep getting a error. This is the error i keep getting:
System.Data.OleDb.OleDbException was unhandled
ErrorCode=-2147217900
Message=Syntax error in FROM clause.
Source=Microsoft Office Access Database Engine
odaCurrency.Dispose()
Dim intcount As Integer
Dim strCurrencyType As String = Currency_NameComboBox.Text
Dim decUSDollars As Decimal = Convert.ToDecimal(txtUSDollars.Text)
Dim decConverted As Decimal
Dim decMulitlplyer As Decimal
For intcount = 0 To datCurrency.Rows.Count - 1
If strCurrencyType = Convert.ToString(datCurrency.Rows(intcount)("Currency Name")) Then
decMulitlplyer = Convert.ToDecimal(datCurrency.Rows(intcount)("Amount"))
decConverted = decUSDollars * decMulitlplyer
Me.lblDollars.Text = decUSDollars.ToString("C") & (" is equal to")
Me.lblConverted.Text = decMulitlplyer.ToString("F") & strCurrencyType
End If
Next
End Sub
-
Jul 31st, 2010, 01:35 PM
#2
Re: Syntax error in FROM clause.
Is your table really called Currency? I would definitely avoid that name, as it is likely to be a key word, and therefore reserved. You might rename it tblCurrency, as an example. Another thing you might try is enclosing the name in square brackets [], but I prefer using a different name for the table.
My usual boring signature: Nothing
 
-
Jul 31st, 2010, 02:04 PM
#3
Thread Starter
New Member
Re: Syntax error in FROM clause.
the whole bracket thing worked. I just found that on a different site. I'm going to see if currency is a keyword or not though. Thanx.
-
Jul 31st, 2010, 02:23 PM
#4
Thread Starter
New Member
Re: Syntax error in FROM clause.
And yes currency is a keyword. I changed the name of the database and redid to connection and it worked just fine.
Thanx for your help.
-
Jul 31st, 2010, 06:00 PM
#5
Re: [RESOLVED] Syntax error in FROM clause.
Whenever you have a real word, such as Currency, it is often just safest to prepend something to it such that it is NOT a word. Many logical table names are multiple words, in which case this isn't a problem, but for a table where the most reasonable name is a single word, prepending something like tbl is just a safe thing to do.
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|