如何使用VB.net在MS Access数据库中编写主键列
您是一个新手,正在学习如何开发一个程序,该程序可以在保存前检查数据库主键列中是否存在某个值,如果存在,则会显示一条消息,指示该数据已退出.
我正在使用ms access db
这是我的代码:
此代码将数据推送到我的表中Ref列保存txtid.text数据
这是ms access dbase中的主键
私有Sub btnsave_Click(ByVal发送者为System.Object,ByVal e为System.EventArgs)处理btnsave.Click
昏暗的cmd作为新的OleDb.OleDbCommand
如果不是con.State = ConnectionState.Open然后
con.Open()
如果结束
cmd.Connection = con
cmd.CommandText =将条目插入(Ref,Fname,Mname,Comment,Gender)"& _
"VALUES("& Me.txtid.Text&,"& Me.txtfname.Text&","& _
Me.txtmname.Text& ","& Me.txtcom.Text& ","& _
Mebogen文本和")"
cmd.ExecuteNonQuery()
''刷新表列表中的数据
Refreshdata()
谢谢
Hi am a newbie learning how to develope a program that can check whether a value exist in the database primary key column before saving it, if it exists it shows a message indicating that that data exits.
I am using ms access db
here is my code:
this code pushes the data into my table the Ref column holds the txtid.text data
which is the primary key in ms access dbase
Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
Dim cmd As New OleDb.OleDbCommand
If Not con.State = ConnectionState.Open Then
con.Open()
End If
cmd.Connection = con
cmd.CommandText = "INSERT INTO entries(Ref,Fname,Mname,Comment,Gender)" & _
"VALUES(" & Me.txtid.Text & ",''" & Me.txtfname.Text & "'',''" & _
Me.txtmname.Text & "'',''" & Me.txtcom.Text & "'',''" & _
Me.cbogen.Text & "'')"
cmd.ExecuteNonQuery()
''refresh data in table list
Refreshdata()
Thanks
选中此
插入,更新,删除和删除带有VB.NET 2005的MS Access 2003中的搜索值 [
Check this
Insert, Update, Delete & Search Values in MS Access 2003 with VB.NET 2005[^]
Hope this help if yes then accept and vote the answer otherwise revert back with queries
--Rahul D.