VB.NET添加新记录问题 [英] VB.NET add new record problem
本文介绍了VB.NET添加新记录问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在处理一个需要用户登录的应用程序。作为此登录过程的一部分,登录时间和日期的详细信息存储在Access DB中。
我使用以下代码来实现此目的,但它只有覆盖表中的第一条记录,每次有人登录时都不会添加新记录。有人指向正确的方向可以让它工作吗?
Hi,
I am currently working on an application that required users to login. As part of this login procedure, details of the time and date of login are stored in an Access DB.
I have used the following code to achieve this, but it only overwrites the first record in the table, it doesn't add a new record each time someone logs in. Could someone point in in the right direction to get this to work?
strSQL = "INSERT INTO tbl_login_history(username, login_date, login_time) VALUES (@user_real_name, @login_date, @login_time)"
cmd = New OleDbCommand(strSQL, objconn)
cmd.Parameters.Clear()
cmd.Parameters.AddWithValue("@user_real_name", user_real_name)
cmd.Parameters.AddWithValue("@login_date", DateTime.Now.ToString("dd/mm/yyyy"))
cmd.Parameters.AddWithValue("@login_time", DateTime.Now.ToString("HH:mm"))
cmd.ExecuteNonQuery()
objconn.Close()
Catch ex As Exception
MsgBox(ex.Message, "Error")
End Try
推荐答案
插入语句总是插入一个新行问题很可能在其他地方。
几件事要检查:
- ExecuteNonQuery的返回值是多少,受影响的行数是多少?
- 是打开正确访问数据库的连接吗?
- 是项目的访问数据库部分,在编译应用程序时是否会在bin文件夹中被覆盖?
- 您是否有正在进行的交易但是在关闭连接之前没有提交?
- 任何错误?
Insert statement always inserts a new row so the problem is most likely elsewhere.
Few things to check:
- what is the return value of the ExecuteNonQuery, how many rows were affected?
- is the connection opened to the correct access db?
- is the access db part of the project, does it get overwritten in bin folder when the applciation is compiled?
- do you have an on-going transaction but you don't commit before closing the connection?
- any errors?
这篇关于VB.NET添加新记录问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文