vb.netsql-server-ceoledboledbdataadapter

Why does Application close after executing a SQL Server CE update command?


My application closes after I execute an update command via oledb connection I also use DataAdapter but it closes without any error too, I can execute insert, delete and select command with out problem.

My DataAdapter commands

dta = New OleDb.OleDbDataAdapter("select * from [information]", con)
dta.UpdateCommand = New OleDb.OleDbCommand("UPDATE [information] SET [needfile]=@needfile,[nofile]=@nofile," &
                    "[subscription]=@subscription,[id]=@id,[name]=@name,[address]=@address,[tel]=@tel,[phone]=@phone" &
                    " WHERE [idn]=@idn", con)
dta.InsertCommand = New OleDb.OleDbCommand("INSERT INTO [information]([needfile],[nofile],[subscription],[id],[name],[address],[tel],[phone]) " &
                    "VALUES (@id,@name ,@address ,@tel ,@phone)", con)
dta.DeleteCommand = New OleDb.OleDbCommand("DELETE FROM [information] WHERE [idn] = @idn", con)

i try this

If con.State = ConnectionState.Closed Then con.Open()
dts = DataGridView1.DataSource
dta.UpdateCommand.Parameters.Clear()
dta.UpdateCommand.Parameters.Add(New OleDb.OleDbParameter("@needfile", dts.Tables(0).Rows(e.RowIndex)(1)))
dta.UpdateCommand.Parameters.Add(New OleDb.OleDbParameter("@nofile", dts.Tables(0).Rows(e.RowIndex)(2)))
dta.UpdateCommand.Parameters.Add(New OleDb.OleDbParameter("@subscription", dts.Tables(0).Rows(e.RowIndex)(3)))
dta.UpdateCommand.Parameters.Add(New OleDb.OleDbParameter("@id", dts.Tables(0).Rows(e.RowIndex)(4)))
dta.UpdateCommand.Parameters.Add(New OleDb.OleDbParameter("@name", dts.Tables(0).Rows(e.RowIndex)(5)))
dta.UpdateCommand.Parameters.Add(New OleDb.OleDbParameter("@address", dts.Tables(0).Rows(e.RowIndex)(6)))
dta.UpdateCommand.Parameters.Add(New OleDb.OleDbParameter("@tel", dts.Tables(0).Rows(e.RowIndex)(7)))
dta.UpdateCommand.Parameters.Add(New OleDb.OleDbParameter("@phone", dts.Tables(0).Rows(e.RowIndex)(8)))
dta.UpdateCommand.Parameters.Add(New OleDb.OleDbParameter("@idn", dts.Tables(0).Rows(e.RowIndex)(0)))
dta.Update(dts)
dts.AcceptChanges()

or

...
dta.UpdateCommand.Prepare()
dta.UpdateCommand.ExecuteNonQuery()

or

...
UpdateCmd.ExecuteNonQuery()

I also tried dta.UpdateCommand.ExecuteNonQuery() and it works the same, my program exits!

Even when I do this manually with OleDbCommand, my program exits without any error.

Thanks.


Solution

  • Using .NET OleDb with SQL Compact from .NET is not supported, please use the ADO.NET provider instead (System.Data..SqlServerCe)