问题描述
Hi
表Film具有ID和Film列.列ID是一个主键和一个自动编号.
当我使用此代码时,连接的版本可以正常工作.
Hi
The table Film has columns ID and Film. The column ID is a primarykey and an autonumber.
When I'm using this code, the connected version, it works fine.
strSQL = 插入胶片(胶片)值(?)"
strSQL = "Insert into Film (Film) values(?)"
cmorder = 新字体> OleDb.OleDbCommand(strSQL,conn)
cmorder = New OleDb.OleDbCommand(strSQL, conn)
Me .dFilmAdpt.InsertCommand = cmorder
Me.dFilmAdpt.InsertCommand = cmorder
Me .dFilmAdpt.InsertCommand .Parameters.Add( "Film" ,OleDbType.LongVarChar)
Me.dFilmAdpt.InsertCommand.Parameters.Add("Film", OleDbType.LongVarChar)
conn.Open()
conn.Open()
dFilmAdpt .InsertCommand.Parameters(table).Value = cbo.Text
dFilmAdpt .InsertCommand.ExecuteNonQuery()
dFilmAdpt.InsertCommand.Parameters(table).Value = cbo.Text
dFilmAdpt.InsertCommand.ExecuteNonQuery()
conn.Close()
但是当我使用断开连接的版本时,它不起作用.我已经知道我可以使用OnRowUpdated和@@ identity,但是我不明白为什么在我使用executenonquery时它起作用,而在我不使用时就不起作用.与数据库的连接或断开连接有任何关系.
da.Fill(ds, 电影" )
conn.Close()
But when I'm using the disconnected version it doesn't work. I have seen that I can use OnRowUpdated and @@identity, but I don't undertstand why it works when I'm using executenonquery and not when I don't. Has it anything with connection or disconnection to the database.
da.Fill(ds, "Film")
dt = ds.Tables( 电影" )
dt = ds.Tables("Film")
Dim insCommand 为 新建 OleDbCommand( "插入Film(Film)values(?)" ,conn)
Dim insCommand As New OleDbCommand("insert into Film(Film)values(?)", conn)
暗淡 为 新建 OleDbParameter
Dim par As New OleDbParameter
par.ParameterName = 电影"
par.ParameterName = "Film"
par.SourceColumn = " ;电影"
par.SourceColumn = "Film"
insCommand.Parameters.Add(par)
insCommand.Parameters.Add(par)
dFilmAdpt.InsertCommand = insCommand
dFilmAdpt.InsertCommand = insCommand
Dim newRow = dt. NewRow
Dim newRow = dt.NewRow
newRow( 电影" )= cbo.Text
newRow("Film") = cbo.Text
dt.Rows.Add(newRow)
dFilmAdpt.Update(ds)
dt.Rows.Add(newRow)
dFilmAdpt.Update(ds)
请解释,并请准确解释
Fia
推荐答案
这篇关于为什么在我使用executenonquery时不必使用@@ identity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!