| | |
Connect to ms access with vb.net
Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Aug 2009
Posts: 5
Reputation:
Solved Threads: 0
Hi expert,
i facing a problem when i try to connect to database by using vb.net
below is my code:
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim dSet As New DataSet
Dim da As OleDb.OleDbDataAdapter
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Dim User, pass ', dataPass
If txtUser.Text = "" Then
lblErr.Text = "Nothing"
Else
lblErr.Text = "Here"
End If
User = txtUser.Text
pass = txtPass.Text
Dim conn As New OleDb.OleDbConnection
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=C:\user.mdb"
conn.Open()
Dim strSQL As String
strSQL = "SELECT * FROM user&pass where username = 'admin'"
da = New OleDb.OleDbDataAdapter(strSQL, conn)
Dim ds As DataSet = New DataSet()
da.Fill(ds) 'fill dataset
Dim dr As DataRow
For Each dr In ds.Tables(0).Rows 'Show results in output window
txtPass.Text = dr("password")
Next
End Sub
And the error message was:
System.Data.OleDb.OleDbException was unhandled
ErrorCode=-2147217900
Message="Syntax error in FROM clause."
Source="Microsoft Office Access Database Engine"
StackTrace:
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) at TestingDatabase.Form1.btnLogin_Click(Object sender, EventArgs e) in C:\Documents and Settings\Chong\My Documents\Visual Studio 2008\Projects\TestingDatabase\TestingDatabase\Form1.vb:line 30 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(ApplicationContext context) at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine) at TestingDatabase.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Can anyone help me find out what is the problem at here? Please help, its urgent...
thanks in advance...
Regards
Mike
i facing a problem when i try to connect to database by using vb.net
below is my code:
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim dSet As New DataSet
Dim da As OleDb.OleDbDataAdapter
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Dim User, pass ', dataPass
If txtUser.Text = "" Then
lblErr.Text = "Nothing"
Else
lblErr.Text = "Here"
End If
User = txtUser.Text
pass = txtPass.Text
Dim conn As New OleDb.OleDbConnection
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=C:\user.mdb"
conn.Open()
Dim strSQL As String
strSQL = "SELECT * FROM user&pass where username = 'admin'"
da = New OleDb.OleDbDataAdapter(strSQL, conn)
Dim ds As DataSet = New DataSet()
da.Fill(ds) 'fill dataset
Dim dr As DataRow
For Each dr In ds.Tables(0).Rows 'Show results in output window
txtPass.Text = dr("password")
Next
End Sub
And the error message was:
System.Data.OleDb.OleDbException was unhandled
ErrorCode=-2147217900
Message="Syntax error in FROM clause."
Source="Microsoft Office Access Database Engine"
StackTrace:
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) at TestingDatabase.Form1.btnLogin_Click(Object sender, EventArgs e) in C:\Documents and Settings\Chong\My Documents\Visual Studio 2008\Projects\TestingDatabase\TestingDatabase\Form1.vb:line 30 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(ApplicationContext context) at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine) at TestingDatabase.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Can anyone help me find out what is the problem at here? Please help, its urgent...
thanks in advance...
Regards
Mike
Last edited by Steammike; Aug 25th, 2009 at 12:49 pm.
•
•
Join Date: May 2008
Posts: 12
Reputation:
Solved Threads: 1
"SELECT * FROM user&pass where username = 'admin'"
Is the table named user&pass?
You might try enclosing it in brackets.
"SELECT * FROM [user&pass] where username = 'admin'"
Is the table named user&pass?
You might try enclosing it in brackets.
"SELECT * FROM [user&pass] where username = 'admin'"
![]() |
Similar Threads
- how to connect my data base in vb.net (VB.NET)
- how to connect ms access database to html webpage (JavaScript / DHTML / AJAX)
- Problem with connect to MS Access... (C#)
- connect database with vb.net form (Geeks' Lounge)
- how to update an access DB with vb.net? (ASP.NET)
- Need help with ms access and vb.net (VB.NET)
- any1 knw how 2 connect access data to dW cs3 (Database Design)
- how to connect access with vb.net (VB.NET)
- connect with access (Visual Basic 4 / 5 / 6)
Other Threads in the VB.NET Forum
- Previous Thread: MAXIMUM number of Forms that can be added in single project in VB 6.0
- Next Thread: A Popup Data Transfer Problem
| Thread Tools | Search this Thread |
.net .net2008 2008 access advanced application array basic beginner browser button buttons center checkbox click client code combo convert cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic eclipse excel exists fade filter forms function generatetags gridview html images input internet listview map mobile module monitor msaccess net number objects open panel pdf picturebox picturebox2 port position print printing read regex remove right-to-left save search searchvb.net serial settings shutdown socket sorting sqldatbase sqlserver survey temperature textbox timer timespan transparency txttoxmlconverter user usercontol validation vb vb.net vba vbnet visual visualbasic visualbasic.net visualstudio.net web winforms winsock wpf wrapingcode xml year





