I have been trying to work this out for the last 4 weeks and cannot find the answer I've just been going around in circles. I have had multiple errors with con As New OleDb.OleDbConnection and connection string and ISAM's
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
Dim da As OleDb.OleDbDataAdapter
Public sql As String
Dim ds As New DataSet
Dim dbPassword As String
dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = "C:\Users\Edward\Desktop\Edward\DataBase Login Window\Users.mdb;Jet OLEDB:Database"
con.ConnectionString = dbProvider & dbSource
con.Open()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
sql = "SELECT * FROM users WHERE accUsername='" & TextBox1.Text & "'AND accPass='" & TextBox2.Text & "'"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "users")
If ds.Tables("users").Rows.Count = 1 Then
Dim isAdmin As Boolean = ds.Tables("users").Rows(0).Item(4)
If isAdmin = True Then
MsgBox("Logged in.")
Form4.Show()
Form4.Username = TextBox1.Text
Form4.Password = TextBox2.Text
ElseIf isAdmin = False Then
MsgBox("Logged in user.")
Form6.Show()
Form6.Username = TextBox1.Text
Form6.Password = TextBox2.Text
End If
Else
MsgBox("Incorrect Username or Password")
End If
Me.Hide()
ds.Clear()
Me.Refresh()
End Sub
Private Sub createanaccount_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles createanaccount.Click
Form2.ShowDialog()
End Sub
End Class
in the button you should set the connectionString here is an example.
dim con as new SQLConnection/OLEDBConnection
con.ConnectionString="Provide your connection string"
con.open
I hope this will definitely solve your problem
Related
my problem is how to search data and update it in ms access and vb.net
my code:
Imports System.Data.OleDb
Public Class Form5
Dim provider As String
Dim dataFile As String
Dim connString As String
Public myConnection As OleDbConnection = New OleDbConnection
Public dr As OleDbDataReader
Private Sub Form5_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
dataFile = "C:\Users\Admin\Desktop\project database\Database5.accdb"
connString = provider & dataFile
myConnection.ConnectionString = connString
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click
myConnection.Open()
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
TextBox7.Clear()
TextBox8.Clear()
TextBox9.Clear()
TextBox10.Clear()
TextBox11.Clear()
Dim str As String
str = "SELECT * FROM registration WHERE (Name = '" & TextBox1.Text & "')"
Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
dr = cmd.ExecuteReader
While dr.Read()
TextBox2.Text = dr("No").ToString
TextBox3.Text = dr("Name").ToString
TextBox4.Text = dr("Age").ToString
TextBox5.Text = dr("Gender").ToString
TextBox6.Text = dr("Phone").ToString
TextBox7.Text = dr("Address").ToString
TextBox8.Text = dr("Desease").ToString
TextBox9.Text = dr("RoomNo").ToString
TextBox10.Text = dr("Building").ToString
TextBox11.Text = dr("RoomType").ToString
End While
myConnection.Close()
End Sub
End Class
the error I'm getting:
"No value given for one or more required parameters."}
Isn't the issue here that when you click button3 you clear the textbox1 where I assume you type the name you wish to search. So its throwing you an error that there is nothing in that field. And even if you type something after wards, and click the button again, it will clear it again before it starts searching. so basically, you're searching for nothing.
Public Class Form1
Dim provider As String
Dim datafile As String
Dim connstring As String
Public myconnection As OleDbConnection = New OleDbConnection
Public dr As OleDbDataReader
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
provider = "Provider=Microsoft.Ace.OLEDB.12.0"
datafile = "Data Source=C:\Users\fess\Desktop\test\compress.accdb"
connstring = provider & ";" & datafile
myconnection.ConnectionString = connstring
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
myconnection.Open()
Dim str As String
str = "SELECT 'name' FROM test2 WHERE 'ID'='1'"
Dim cmd As OleDbCommand = New OleDbCommand(str, myconnection)
dr = cmd.ExecuteReader
TextBox1.Text = dr(str).ToString
myconnection.Close()
End Sub
End Class
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
myconnection.Open()
Dim str As String
str = "SELECT ID from test2 where name='bry'"
Dim cmd As OleDbCommand = New OleDbCommand(str, myconnection)
dr = cmd.ExecuteReader
While dr.Read()
TextBox1.Text = dr("ID").ToString
End While
myconnection.Close()
Found my mistake after a bit of searching
I am a beginner at databases with VB.Net and am trying to update a password (field) in a database and I keep getting an error:
"Syntax error in query expression '((UID = ?) AND ((? = 1 AND Username IS NULL) OR (Username = ?)) AND ((? = 1 AND Firstname} IS NULL) OR (Firstname} = ?)) AND ((? = 1 AND Surname IS NULL) OR (Surname = ?)) AND ((? = 1 AND UPassword IS NULL) OR (UPassword = ?)) AND ((? = 1 AND DOB IS NULL)'."
Here is the code for the form it corresponds to and happens when the reset button is clicked.
Public Class ResetPW
Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim sql As String
Dim dbProvider As String
Dim dbSource As String
Dim da As New OleDb.OleDbDataAdapter
Private Sub cbxShowchar_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxShowchar.CheckedChanged
If cbxShowchar.Checked = True Then
txtNewpassword.PasswordChar = ""
txtVNewpassword.PasswordChar = ""
Else
txtNewpassword.PasswordChar = "*"
txtVNewpassword.PasswordChar = "*"
End If
End Sub
Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
Me.Close()
Form2.Show()
End Sub
Private Sub ResetPW_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dbProvider = "PROVIDER=Microsoft.ACE.OLEDB.12.0;"
dbSource = "DATA Source = C:\Users\Luke\Dropbox\FdSc Computing\Year 2\Project\Product\Book Database.accdb"
con.ConnectionString = dbProvider & dbSource
con.Open()
sql = "SELECT * FROM T_Users"
da = New OleDb.OleDbDataAdapter(Sql, con)
da.Fill(ds, "Users")
MsgBox("The database is now open")
con.Close()
MsgBox("The database is now closed")
End Sub
Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
If txtNewpassword.Text = txtVNewpassword.Text Then
Dim cb As New OleDb.OleDbCommandBuilder(da)
ds.Tables("Users").Rows(0).Item(4) = txtNewpassword.Text
da.Update(ds, "Users") 'ERROR HAPPENS HERE'
MsgBox("Password Reset", vbInformation)
Else
MsgBox("The passwords do not match", vbExclamation)
End If
End Sub
End Class
I would be very grateful for any help. Thanks guys!
I am getting an error "Syntax error in Update statement" from code below:
Public Class Emp
Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
Dim ds As New DataSet
Dim da As New OleDb.OleDbDataAdapter
Dim sql As String
Dim inc As Integer
Dim MaxRows As Integer
Private Sub Emp_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dbProvider = "Provider=Microsoft.Ace.OLEDB.12.0;"
dbSource = "Data Source = C:\Users\Blessing\Documents\IBCARIP.accdb"
con.ConnectionString = dbProvider & dbSource
con.Open()
sql = "SELECT * From Employees"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "IBCARIP")
'con.Close()
txtID.Text = ds.Tables("IBCARIP").Rows(0).Item(0)
txtName.Text = ds.Tables("IBCARIP").Rows(0).Item(1)
MaxRows = ds.Tables("IBCARIP").Rows.Count
inc = -1
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If InputBox("Please enter Clearance Level 1 Code", ) <> "me" Then
MsgBox("Invalid clearence code entered. Please make sure you have enough previlegies to perfom this operation..!", MsgBoxStyle.OkOnly)
Else
Dim cb As New OleDb.OleDbCommandBuilder(da)
ds.Tables("IBCARIP").Rows(inc).Item(0) = txtID.Text
ds.Tables("IBCARIP").Rows(inc).Item(1) = txtName.Text
da.Update(ds, "IBCARIP") <<<<<<<<<<<<<<<<<<<<<<<<<<<<SYNTAX ERROR IN UPDATE STATEMENT
End If
End Sub
Can someone please help
I am using a form having 10 text boxes,1 register button & 1 exit button. I have created the database in MS Access 2007 and saved the file in desktop. I have connected by "Add New Data Source". Provider & Path is:Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\sipl\Desktop\Cust_Dtl.mdb. But when I click register the following error is showing:
con.Open() - Doesn't have a valid file name.
Here is my code:
Public Class Form2
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim constring As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Users\sipl\Desktop\Cust_Dtl.mdb" & System.IO.Directory.GetCurrentDirectory & "Cust_Dtl.mdb"
Dim insertcmd As System.Data.OleDb.OleDbCommand = New System.Data.OleDb.OleDbCommand
Dim con As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection
con.ConnectionString = constring
insertcmd.CommandType = CommandType.Text
insertcmd.CommandText = String.Format("INSERT INTO {0} VALUES ('{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}')", "Table1", TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text, TextBox5.Text, TextBox6.Text, TextBox7.Text, TextBox8.Text, TextBox9.Text, TextBox10.Text)
insertcmd.Connection = con
con.Open()
Try
insertcmd.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
con.Close()
End Sub
End Class
Please help to fix this problem. Thanks.
You are calling the database string twice:
Dim constring As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Users\sipl\Desktop\Cust_Dtl.mdb" & System.IO.Directory.GetCurrentDirectory & "Cust_Dtl.mdb"
This gives the string "C:\Users\sipl\Desktop\Cust_Dtl.mdbC:\Users\sipl\Desktop\Cust_Dtl.mdb"
Remove either C:\Users\sipl\Desktop\Cust_Dtl.mdb"
or & System.IO.Directory.GetCurrentDirectory & "Cust_Dtl.mdb