Net Syntax Error In From Clause
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about
Syntax Error In From Clause Vb6
Stack Overflow the company Business Learn more about hiring developers or posting ads with syntax error in from clause access us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is syntax error in from clause excel a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up syntax error in FROM clause in vb.net up vote -1 down vote favorite Dim
Syntax Error In From Clause Union Query
nm As String Dim pass As String nm = TextBox1.Text pass = TextBox2.Text Try cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Pavilion\Documents\Visual Studio 2010\Projects\WindowsApplication5\Ent.accdb" cn.Open() Dim sql As String sql = "SELECT * FROM user WHERE UName='" & nm & "'AND Pwd='" & pass & "'" cmd = New OleDbCommand(sql, cn) dr = cmd.ExecuteReader While (dr.Read()) If ((nm.Equals(dr(0))) And pass.Equals(dr(1))) Then MessageBox.Show("Login Sucessful") End If End While Catch ex As Exception MsgBox("Login Failed :" & ex.Message) End Try This code is giving the following error syntax error in FROM clause vb.net share|improve this question edited May 9 '14 at 5:08 Tim 21.7k33748 asked May 9 '14 at 4:13 Priyanshu 43 add a comment| 3 Answers 3 active oldest votes up vote 1 down vote If the code you posted is copy and paste, you're missing a space between the username and the AND keyword. Your code: "SELECT * FROM user WHERE UName='" & nm & "'AND Pwd='" & pass & "'" Should be: "SELECT * FROM user WHERE UName='" & nm & "' AND Pwd='" & pass & "'" However, you should use parameterized queries to avoid the possibility of SQL injection attacks. Something like this: sql = "SELECT * FROM user WHERE UName=@nm AND Pwd=@pass" cmd = New OleDbCommand(sql, cn) cmd.Parameters.AddWithValue("@nm", TextBox1.Text) cmd.Parameters.AddWithValue("@pass", TextBox2.Text) cmd.CommandType = CommandType.Text dr = cmd.ExecuteReader share|improve this answer answered May 9 '14 at 5:00 Tim 21.7k33748 add a comment| up vote 0 down vote @Tim is correct, but I think you might also have problem with your SQL as user is a reserved word. If I execute SELECT * FROM user WHERE UName='fred' AND Pwd='123' in SQL Server I get told Incorrect syntax near the keyword 'u
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Syntax error in FROM clause in Visual Basic up vote 0 down vote favorite http://stackoverflow.com/questions/23556496/syntax-error-in-from-clause-in-vb-net i'm having trouble fixing this problem "Syntax error in FROM Clause" Here's my codes: Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click myConnetion = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\iponz18\Documents\Visual Studio 2012\Projects\CanteenBillingSystem\CanteenBillingSystem\CanteenBillingSystem.accdb") Dim table As String = "SELECT UserID FROM User WHERE UserID = " + TextBox1.Text + ";" da = New OleDbDataAdapter(table, myConnetion) ds = New DataSet da.Fill(ds, "User") http://stackoverflow.com/questions/30355379/syntax-error-in-from-clause-in-visual-basic If (ds.Tables("User").Rows.Count > 0) Then Form2.Show() Me.Close() End If End Sub The error is on this line: da.Fill(ds, "User") please help me out... vb.net share|improve this question asked May 20 '15 at 16:27 John Carlo Ponte 1 1 Have you tried wrapping the User table name with [] - ie. SELECT UserID from [User] .. User is normally a reserved keyword. –theduck May 20 '15 at 16:32 Try to use backquotes. Maybe user is a reserved keyword. Allthough I would doubt that, but well, if it is then backquotes will tell it that you are talking about a table. –user458577 May 20 '15 at 16:33 add a comment| 1 Answer 1 active oldest votes up vote 3 down vote User is a reserved keyword in MS-Access. You need to put it between square brackets Dim table As String = "SELECT UserID FROM [User] WHERE UserID = ... Said that, your query has other problems. A better approach is this one: Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim table As String = "SELECT UserID FROM User WHERE UserID = @uid" Using conn = New OleDbConnection(.....) Using da = New OleDbDataAdapter(table, conn ) da.SelectCommand.Parameters.Add("@uid", OleDbType.VarWChar).Value = textBox1.Text ds = New DataSet da.Fill(ds, "User") I
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the http://www.vbforums.com/showthread.php?471019-RESOLVED-Syntax-error-in-FROM-clause forum that you want to visit from the selection below. Results 1 to 5 of 5 Thread: [RESOLVED] Syntax error in FROM clause Tweet Thread Tools Show Printable Version Subscribe to this Thread… Display Linear Mode Switch http://p2p.wrox.com/vb-databases-basics/79411-syntax-error-clause.html to Hybrid Mode Switch to Threaded Mode May 26th, 2007,08:07 AM #1 girl81 View Profile View Forum Posts Thread Starter Addicted Member Join Date Apr 2006 Location Malaysia Posts 211 [RESOLVED] Syntax error in FROM clause Hi syntax error all..i was wondering with this error message.. "Syntax error in FROM clause. Run time error '-2147217900' This error happened for Update and Add process when i retrieved the Table PRODUCT from Access..there is no error message again when i change table name PRODUCT to PRODUCT1.. Thanks in advance.. Reply With Quote May 26th, 2007,10:13 AM #2 si_the_geek View Profile View Forum Posts Super Moderator Join Date Jul 2002 Location Bristol, UK Posts 38,317 Re: Syntax syntax error in error in FROM clause Moved to Database Development forum - which is where SQL/database related questions belong It sounds like Product is a reserved word.. presumably because there is a function with the same name (so there is confusion in working out whether you meant the function, or the table) The ideal solution is what you have done... change the table name. (July 2007 to June 2017) . . . . . . . . . . Hitchhiker's Guide to Getting Help at VBForums Classic VB FAQs (updated Oct 2010) ...Database Development FAQs/Tutorials (updated May 2011) (includes fixing common VB errors) .......... (includes fixing common DB related errors, and [Classic VB] ADO tutorial /further steps, and [VB.Net] ADO.Net Tutorial). Tutorial: How to automate Excel from VB6 (or VB5/VBA) .•. SQL 'Select' statement formatter/checker .•. Convert colour number to colour name .•. FlexGrid: fill from recordset .•. FlexGrid: AutoSize columns .•. DB Reserved Words checker Connection strings .•. MDAC/Jet/ACE downloads .•. SQL Server downloads .•. MZTools (free upgrade for the VB6/VBA Editor) Reply With Quote May 27th, 2007,08:00 AM #3 girl81 View Profile View Forum Posts Thread Starter Addicted Member Join Date Apr 2006 Location Malaysia Posts 211 Re: Syntax error in FROM clause Originally Posted by si_the_geek Moved to Database Development forum - which is where SQL/database related questions belong It
Unanswered Topics Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics Syntax error in FROM clause. User Name Remember Me? Password Reminder Password Register Register | FAQ | Members List | Calendar | Today's Posts | Search VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums. Search Forums Show Threads Show Posts Advanced Search Find All Thanked Posts Go to Page... Welcome to the p2p.wrox.com Forums. You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free . Thread Tools Display Modes #1 (permalink) May 14th, 2010, 03:23 PM jaz061459 Registered User Join Date: May 2010 Posts: 6 Thanks: 0 Thanked 0 Times in 0 Posts Syntax error in FROM clause. I am running the following code: Dim MDBInfoCMD As ADODB.Command Dim lngInfoCnt As Integer VSGSAMDB is active conection strSAMTotCntSql declared Set VGInfoTable = New ADODB.Recordset Set MDBInfoCMD = New ADODB.Command Set MDBInfoCMD.ActiveConnection = VSGSAMDB MDBInfoCMD.CommandText = strSAMTotCntSql strSAMTotCntSql = "SELECT Count([MDB Information].converted) AS Cnt FROM [MDB Information];" VGInfoTable.Open strSAMTotCntSql, VSGSAMDB, adOpenKeyset, adLockOptimistic, adCmdTable Having no issues at all to run this within the database, but in VB6 code i am getting the following error: ?err.Descriptio