【发布时间】:2014-07-09 15:11:10
【问题描述】:
我在具有以下架构的数据库中有一个表“tblAuthors”(ID 主键自动增量,Author_Name Varchar)
表是空的。我正在尝试将记录插入表中。这是我的代码
Public Sub insertData()
Me.mystr = "INSERT INTO tblAuthors (Author_Name) VALUES (@Author_Name)"
modAdoDB.SetConnection()
Me.mySQLiteCommand = New SQLiteCommand(Me.mystr, modAdoDB.con)
Me.mySQLiteCommand.CommandText = Me.mystr
Me.mySQLiteCommand.Parameters.AddWithValue("@Author_Name", frmAddAuthor.txtAuthorName.Text)
Me.mySQLiteCommand = con.CreateCommand()
Me.mySQLiteCommand.ExecuteNonQuery()
frmAddAuthor.Close()
MsgBox("Author record has been added.", MsgBoxStyle.Information, "Library")
modAdoDB.CloseConnection()
End Sub
我收到错误消息 Value cannot be null 参数名称:s
ps 我可以从数据库中读取。 提前致谢
【问题讨论】:
-
删除下面一行
Me.mySQLiteCommand = con.CreateCommand()。 -
@Bjørn-Roger Kringsjå 当我删除 Me.mySQLiteCommand = con.CreateCommand() 行时,我得到数据库被锁定
-
Jess,你需要打开连接。在
Me.mySQLiteCommand.ExecuteNonQuery()之前调用Me.mySQLiteCommand.Connection.Open()。