VB.Net 2015 Enterprise和MS-Access 2010中的注册表 [英] Registration Form in VB.Net 2015 Enterprise and MS-Access 2010

查看:119
本文介绍了VB.Net 2015 Enterprise和MS-Access 2010中的注册表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用Ms-Access 2010和Visual Studio 2015 Enterprise我想创建一个带字段的注册表单



名称为文本



Address as Text



许可证编号与文本和数字混合



数量为数字



提交日期为DD / MM / YYYY



我想将它连接到名为example.accdb的MS-Access 2010数据库我的代码是 

 

Imports System.Data.OleDb
Public Class Form1
Dim provider As String
Dim dataFile As String
Dim connString As String
Dim con As OleDbConnection = New OleDbConnection
Private Sub Button2_Click(sender As Object,e As EventArgs)处理Button2.Click
Me.Close()
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs)处理Button1.Click
provider =" Provider = Microsoft.ACE.OLEDB.12.0; Data Source = E:\ example.accdb"
connString = provider
con。 ConnectionString = connString
con.Open()
Dim str As String
str =" Insertinto tbl([Fname],[Address],[LicenseNumber],[Amount],[Submittedon] )值(?,?,?,?,?,?)"
Dim cmd As OleDbCommand = New OleDbCommand(str,con)
cmd.Parameters.Add(New Ole) DbParameter(" Fname",CType(TextBox1.Text,String)))
cmd.Parameters.Add(New OleDbParameter(" Address",CType(TextBox2.Text,String)))
cmd .Parameters.Add(New OleDbParameter(" LicenseNumber",CType(TextBox3.Text,String)))
cmd.Parameters.Add(New OleDbParameter(" Amount",CType(TextBox4.Text,String)) )
cmd.Parameters.Add(New OleDbParameter(" Submittedon",CType(DateTimePicker1。,String)))
尝试
cmd.ExecuteNonQuery()
cmd.Dispose( )
con.Close()
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
C ex ex As Exception
MsgBox(" error")

End Try
End Sub

End Class





我点击提交时出现此错误(Button1)System.Data.dll中出现未处理的"System.InvalidOperationException"类型异常



附加信息:不允许更改'ConnectionString'属性。连接的当前状态是打开的。



i想要从DateTimePicker1获取日期并将其保存到数据库example.accdb并希望获取两个日期之间的所有值。

解决方案

您好,


您拥有的INSERT正在连接,例如



应该是


INSERT INTO


要查看高级代码示例,请参阅我的MSN代码示例并忽略DataGridView方面


https://code.msdn.microsoft.com/Adding-new-records-into-53ce3eb1?redir=0


I am having Ms-Access 2010 and Visual studio 2015 Enterprise I wanna create a registration form with fields

Name as Text

Address as Text

License Number mingled with text and number

Amount as Number

Submitted Date as DD/MM/YYYY

I want to connect it with MS-Access 2010 Database named example.accdb My code is 

Imports System.Data.OleDb Public Class Form1 Dim provider As String Dim dataFile As String Dim connString As String Dim con As OleDbConnection = New OleDbConnection Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Me.Close() End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\example.accdb" connString = provider con.ConnectionString = connString con.Open() Dim str As String str = "Insertinto tbl([Fname],[Address],[LicenseNumber],[Amount],[Submittedon]) Values (?,?,?,?,?,?) " Dim cmd As OleDbCommand = New OleDbCommand(str, con) cmd.Parameters.Add(New OleDbParameter("Fname", CType(TextBox1.Text, String))) cmd.Parameters.Add(New OleDbParameter("Address", CType(TextBox2.Text, String))) cmd.Parameters.Add(New OleDbParameter("LicenseNumber", CType(TextBox3.Text, String))) cmd.Parameters.Add(New OleDbParameter("Amount", CType(TextBox4.Text, String))) cmd.Parameters.Add(New OleDbParameter("Submittedon", CType(DateTimePicker1., String))) Try cmd.ExecuteNonQuery() cmd.Dispose() con.Close() TextBox1.Clear() TextBox2.Clear() TextBox3.Clear() TextBox4.Clear() Catch ex As Exception MsgBox("error") End Try End Sub

End Class


I get this error when i click submit(Button1) An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.dll

Additional information: Not allowed to change the 'ConnectionString' property. The connection's current state is open.

i want to get date from DateTimePicker1 and save it to database example.accdb and want to get all values between two dates.

解决方案

Hello,

The INSERT you have is concatenating e.g.

It should be

INSERT INTO

To see an advance (to you) code sample see my MSN code sample and ignore the DataGridView aspect

https://code.msdn.microsoft.com/Adding-new-records-into-53ce3eb1?redir=0


这篇关于VB.Net 2015 Enterprise和MS-Access 2010中的注册表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆