【发布时间】:2014-02-19 19:33:37
【问题描述】:
您好,我正在尝试使用 VB express 2010 创建前端用户表单
我已经使用 excel 用户表单和 VBA 完成了这项工作,但大家一致认为这不是一个好主意。我只需要在 Visual Basic 的语法上轻推一下。这是我有连接子的代码是我来自 VBA 的代码。我也不确定我使用的是 VB6 还是 VB.Net
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Part As Integer, Job As Integer, Emp As Integer, Weight As Integer, Oven As Integer
Part = TextBox1.Text
Job = TextBox2.Text
Emp = TextBox3.Text
Weight = TextBox4.Text
Oven = TextBox5.Text
Update()
End Sub
Sub Update()
Using cnn = New OleDBConnection (Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccessFile.accdb;
Persist Security, Info=False;)
cnn.Open()
Dim StrSql = "SELECT * FROM Foam WHERE FoamID = ?"
Using cmd = New OleDbCommand(StrSql, cnn)
cmd.Parameters.AddWithValue("@p1", )
Using reader = cmd.ExecuteReader()
If Not reader.HasRows Then
reader.Close() ' close because the connection cannot serve a command while reader is open
' no match found; add new record .....USING PARAMETERS.....
StrSql = "INSERT INTO Foam VALUES(?,?,?,?,?,?,?,?)"
Using insCmd = New OleDbCommand(SqSql, cnn)
cmd.Parameters.AddWithValue("@p1", ID)
cmd.Parameters.AddWithValue("@p2", Part)
cmd.Parameters.AddWithValue("@p3", Job)
cmd.Parameters.AddWithValue("@p4", Emp)
cmd.Parameters.AddWithValue("@p5", Weight)
cmd.Parameters.AddWithValue("@p6", Oven)
cmd.ExecuteNonQuery()
End Using
Else
reader.Close()
End If
End Using
End Using
End Using
End Sub
End Class
这是我更新的代码;我无法让新的 OleDB 连接工作。我认为我的连接字符串没问题。这应该可以更好地了解我想要完成的任务的性质。
【问题讨论】:
-
如果您使用 Visual Studio,那么您必须为 vb.net 编写代码。你真的把很多完全不同的东西混合在一起
-
我认为整个 Update Sub 将毫无用处。我只是想为我所谈论的内容提供一些背景信息。至少我现在知道我正在使用 VB.net!这将有助于谷歌大声笑。谢谢
-
VB6 是 Visual Basic 6.0,是 Visual Studio 6.0 的一部分。由于您使用的是“Visual Basic”2xxx,因此您使用的是 VB.Net(又名 VFred)而不是 VB6。
标签: vb.net visual-studio-2010 ms-access vb6