error message "Child list for field dbo cannot be created" in last line code
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ds1.Reset()
con1 = New SqlConnection(Strcon)
con1.Open()
strsql1 = "SELECT * FROM dbo.rasmi where Personel_ID=123456"
da1 = New SqlDataAdapter(strsql1, con1)
da1.Fill(ds1, "dbo.rasmi")
con1.Close()
DataGridView1.DataBindings.Clear()
DataGridView1.DataBindings.Add(New Binding("datasource", ds1, "dbo.rasmi"))
End Sub
Imports System.Threading
Imports System.Data
Imports System.Data.SqlClient
Public Class Form2
Dim Strcon As String = "Data Source=.;Initial Catalog=Pooyesh_Reprt;Persist Security
Info=True;User ID=sa;Password=789456321"
Dim con1 As SqlConnection
Dim strsql1 As String = ""
Dim da1 As SqlDataAdapter
Dim ds1 As New DataSet
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim TypeOfLanguage = New System.Globalization.CultureInfo("fa") ' or "fa-IR" for b
Farsi(Iran)
InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(TypeOfLanguage)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ds1.Reset()
con1 = New SqlConnection(Strcon)
con1.Open()
strsql1 = "SELECT * FROM dbo.rasmi where Personel_ID=123456"
da1 = New SqlDataAdapter(strsql1, con1)
da1.Fill(ds1, "dbo.rasmi")
con1.Close()
DataGridView1.DataBindings.Clear()
DataGridView1.DataBindings.Add(New Binding("datasource", ds1, "dbo.rasmi"))
End Sub
End Class
Related
I currently doing the changepassword function in my vb.net project, user can click change password to change their password
But my code doesnt update correctly , it will show "updated" but when i go to my database access table the data still remain the same
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.IO
Public Class frmUserDetail
Dim ds As New DataSet
Dim dt As New DataTable
Dim cmd As SqlCommand
Dim con As SqlConnection
Dim da As New OleDbDataAdapter
Dim conn As New OleDbConnection
Private Sub FrmUserDetail_Load(sender As Object, e As EventArgs) Handles MyBase.Load
conn.ConnectionString = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=..\phoneOnline.accdb;Persist Security Info=false;")
loadUserDetail()
txtUserName.Enabled = False ' set it to false so user cannot do shit with it
End Sub
Public Sub loadUserDetail()
conn.ConnectionString = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=..\phoneOnline.accdb;Persist Security Info=false;")
Dim cmd As OleDbCommand
Dim userName As String = frmMain.lblUserLogin.Text
'specify name of the user
Dim search As String = "SELECT * from tblUser WHERE UserName= '" + userName + "'"
cmd = New OleDbCommand(search)
cmd.Connection = conn
Dim dtt As New DataTable()
Dim daa As New OleDbDataAdapter(cmd)
daa.Fill(dtt)
If dtt.Rows.Count() > 0 Then
txtUserName.Text = dtt.Rows(0)(0).ToString 'show the userName
txtUserPassword.Text = dtt.Rows(0)(1).ToString 'show the password of the user
txtEmail.Text = (dtt.Rows(0)(2).ToString) 'show user email
Else
MsgBox("You are currently login as a guest")
End If
End Sub
Private Sub changePassword()
If cbChangePassword.Checked Then
txtChangePassword.Enabled = True
Else
txtChangePassword.Enabled = Not (True)
End If
End Sub
Private Sub CbChangePassword_CheckedChanged(sender As Object, e As EventArgs) Handles cbChangePassword.CheckedChanged
changePassword()
End Sub
Private Sub BtnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
conn.Open()
Dim cmd As OleDbCommand
Dim sql As String = "UPDATE tblUser SET UserPassword=#userpass,Email=#email WHERE UserName=#userName;"
cmd = New OleDbCommand(sql.ToString, conn)
cmd.Parameters.AddWithValue("#username", txtUserName.Text)
cmd.Parameters.AddWithValue("#userpass", txtChangePassword.Text)
cmd.Parameters.AddWithValue("#email", txtEmail.Text) 'pass the time variable from the form 1 to the parameter
cmd.ExecuteNonQuery()
MsgBox("updated")
conn.Close()
End Sub
Private Sub BtnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Hide()
frmMain.Show()
End Sub
End Class
I Expect my database will get updated when i updated it
I'm trying to have my program update the database when you type in new information and save it, everything else is working in my application but it is not saving my changes when I reload the application. What seems to be the error?
Imports System.IO
Imports System.Data.OleDb
Public Class Form1
Private DBPath As String
Private conn As OleDbConnection
Private adapter As OleDbDataAdapter
Private dtMain As DataTable
Private dataSet As DataSet
Private cmdBuilder As OleDbCommandBuilder
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DBPath = Application.StartupPath + "\MEGACITIES.mdb"
conn = New OleDbConnection(Convert.ToString("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=") & DBPath)
conn.Open()
If Not File.Exists(DBPath) Then
MessageBox.Show("Please copy the mdb to the path: " + Application.StartupPath)
Else
' connect to DB
adapter = New OleDbDataAdapter("SELECT * FROM [Cities]", conn)
Dim builder = New OleDbCommandBuilder(adapter)
dataSet = New DataSet()
adapter.Fill(dataSet, "Cities")
DataGridView1.DataSource = dataSet.Tables("Cities")
End If
End Sub
Private Sub btnPopulationByOrder_Click(sender As Object, e As EventArgs) Handles btnPopulationByOrder.Click
adapter = New OleDbDataAdapter("SELECT * FROM [Cities] order by pop2015", conn)
Dim builder = New OleDbCommandBuilder(adapter)
'dtMain = New DataTable()
'adapter.Fill(dtMain)
'DataGridView1.DataSource = dtMain
dataSet = New DataSet()
adapter.Fill(dataSet, "Cities")
DataGridView1.DataSource = dataSet.Tables("Cities")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
adapter = New OleDbDataAdapter("SELECT Cities.city,Cities.country,Cities.pop1995,Countries.currency FROM [Cities] inner join Countries on Cities.country = Countries.country", conn)
Dim builder = New OleDbCommandBuilder(adapter)
dataSet = New DataSet()
adapter.Fill(dataSet, "Cities")
DataGridView1.DataSource = dataSet.Tables("Cities")
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If TextBox1.Text.Trim() = "" Then
MessageBox.Show("Please enter the country name in text box.")
Else
adapter = New OleDbDataAdapter("SELECT city from [Cities] where country = '" + TextBox1.Text + "'", conn)
Dim builder = New OleDbCommandBuilder(adapter)
dataSet = New DataSet()
adapter.Fill(dataSet, "Cities")
DataGridView1.DataSource = dataSet.Tables("Cities")
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
cmdBuilder = New OleDbCommandBuilder(adapter)
adapter.Update(dataSet, "Cities")
DataGridView1.DataSource = dataSet.Tables("Cities")
MessageBox.Show("1 changed Records were stored", "Project4Spring2016")
End Sub
End Class
You have to do an update sql statement on the records your try to save. It appears right now all you have are select statements
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
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim cnnOLEDB As New OleDbConnection
Dim cmdOLEDB As New OleDbCommand
Dim cmdInsert As New OleDbCommand
Dim cmdDelete As New OleDbCommand
Dim cmdUpdate As New OleDbCommand
Dim conn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= C:\Users\Steven\Desktop\Database.accdb"
Private Sub searchbtn_Click(sender As Object, e As EventArgs) Handles searchbtn.Click
If ssearch.Text <> "" Then
cmdOLEDB.CommandText = "SELECT StudentID from Students Where TP = " & CInt(ssearch.Text)
cmdOLEDB.Connection = cnnOLEDB
Dim rd As OleDbDataReader = cmdOLEDB.ExecuteReader()
If rd.Read = True Then
Form2.Show()
Form2.TextBox1.Text = rd(0).ToString
Else
MessageBox.Show("Information not found in Database")
End If
rd.Close()
End If
Me.Hide()
Form2.Show()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
cnnOLEDB.ConnectionString = conn
cnnOLEDB.Open()
End Sub
Private Sub ssearch_TextChanged(sender As Object, e As EventArgs) Handles ssearch.TextChanged
End Sub
Private Sub insertbtn_Click(sender As Object, e As EventArgs) Handles insertbtn.Click
If ssearch.Text <> "" Then
cmdInsert.CommandText = "INSERT INTO Students (StudentID) VALUES (" & ssearch.Text & ");"
cmdInsert.CommandType = CommandType.Text
cmdInsert.Connection = cnnOLEDB
cmdInsert.ExecuteNonQuery()
MsgBox(ssearch.Text & " " & "Record inserted.")
ssearch.Text = ""
Else
MsgBox("Please Enter Student ID")
End If
cmdInsert.Dispose()
End Sub
End Class
As you can see i can insert data into the database but I can't search it. When I run it it show errors on Dim rd As OleDbDataReader = cmdOLEDB.ExecuteReader()
saying:
No value given for one or more required parameters visual basic error
What was my mistake?
Imports CrystalDecisions.CrystalReports.Engine
Imports System.Data.OleDb
Public Class Form2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim SqlQuery As String = "SELECT * FROM TBLName WHERE ID = " & Form1.Datagridview1.SelectedRows(0).Cells(0).Value.ToString() & ""
Dim SqlCommand As New OleDbCommand
Dim SqlAdepter As New OleDbDataAdapter
Dim Table As New DataTable
With SqlCommand
.CommandText = SqlQuery
.Connection = Form1.conn
End With
With SqlAdepter
.SelectCommand = SqlCommand
.Fill(Table)
End With
Dim crystal As New CrystalReport1
crystal.SetDataSource(Table)
rptviewer.ReportSource = crystal
rptviewer.Refresh()
End Sub
End Class
I'm getting an error on this line
.Connection = Form1.conn
what should I do??