我有两个表masterdb
和markssheetdb
表,我想从表单2到表单1取masterdb
到markssheedb
表的三列,但是它抛出错误,例如“ 它将生成重复的值。”
我正在使用Visual Studio 2017和Msaccess 2017。
Imports System.Data.OleDb
Public Class Home
Dim con As New OleDbConnection
Private Sub Home_Load(sender As Object, e As EventArgs) Handles MyBase.Load
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Desktop\master.accdb"
con.Open()
Datagridshow()
End Sub
Private Sub Datagridshow()
Dim ds As New DataSet
Dim dt As New DataTable
ds.Tables.Add(dt)
Dim da As New OleDbDataAdapter
da = New OleDbDataAdapter("INSERT INTO Smarkssheetdb ( ROLLNO, UNIVROLL, [NAMES] )
SELECT Smasterdb.ROLL_No, Smasterdb.UNIV_ROLL, Smasterdb.NAME
FROM Smasterdb,Smarkssheetdb where Smasterdb.ROLL_No <> Smarkssheetdb.ROLLNO ", con)
da.Fill(dt)
DataGridView1.DataSource = dt.DefaultView
con.Close()
End Sub
Private Sub AddEditToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AddEditToolStripMenuItem.Click
addedit.Show()
End Sub
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
End
End Sub
End Class
在masterdb中,行是Sno,rollno,regno,univroll,课程,名称,sgpa1,sgpa2,.....,sgpa8 在markssheetdb表中,行是rollno,univroll,name,m1,m2,m3,.....,m8
并且我希望两个表中的data rollno,univroll,名称都相同,如果我更新masterdb,它将自动更新markssheetdb表字段。
答案 0 :(得分:0)
在没有插入语句的情况下尝试使用数据适配器
da = New OleDbDataAdapter("SELECT Smasterdb.ROLL_No, Smasterdb.UNIV_ROLL, Smasterdb.NAME
FROM Smasterdb,Smarkssheetdb where Smasterdb.ROLL_No <> Smarkssheetdb.ROLLNO;", con)
您还应该在访问中尝试使用select语句,以查看它们是否正常工作。