我目前正在MS Visual Basic 2008 Express Edition中使用MS Access中的后端数据库。单击添加按钮后,程序将在MS访问中添加计划数据。问题是我不知道如何根据表单中选中的“天数”添加记录(具有相同数据输入的记录,除了来自计划天数字段)。
例如,从上面的给定表单中,我想在MS ACCESS 2010中生成以下输出,该输出显示除sched_days字段之外的类似记录。
截至目前,我有以下代码:
Imports System.Data.OleDb
Public Class AddSchedForm
Private Sub AddSchedForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.CenterToParent()
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
If btnAdd.Text = "Add" Then
Try
Using conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Database.accdb;")
conn.Open()
Dim command As New OleDbCommand("insert into Schedule (prof_id,course_code,section_code,course_title,units,sched_time1,sched_time2,sched_days,sched_room) values (@profid,@coursecode,@sectioncode,@title,@units,@schedtime1,@schedtime2,@schedday,@schedroom)", conn)
With command.Parameters
.AddWithValue("@profid", profID.Text)
.AddWithValue("@coursecode", coursecode.Text)
.AddWithValue("@sectioncode", sectioncode.Text)
.AddWithValue("@title", coursetitle.Text)
.AddWithValue("@units", units.Text)
.AddWithValue("@schedtime1", time1.Text)
.AddWithValue("@schedtime2", time2.Text)
.AddWithValue("@schedday", "Monday")
.AddWithValue("@schedroom", room.Text)
End With
command.ExecuteNonQuery()
MessageBox.Show("Employee's Informations Successfuly Recorded!", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
command.Dispose()
conn.Close()
Close()
End Using
Catch ex As Exception
MessageBox.Show(ex.Message, "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End Sub
End Class
谢谢!