Pregunta

I have attached a local sqlceserver database(version 3.5.8080.0) with my windows forms application project(vb). When i try to insert the data using the following code,

infoReader = My.Computer.FileSystem.GetFileInfo(i)
cmd.CommandText = "insert into log(filename,filesize,cdate) values('" & i & "'," &     infoReader.Length & ",'" & Now.ToString(("yyyy-MM-dd")) & "')"
cmd.Connection = cs
cs.Open()
cmd.ExecuteNonQuery()
cs.Close()

The cs is the sqlceconnection object with following declaration:

Dim strconnection As String = "Data Source=|DataDirectory|\Database1.sdf"
Dim cs As New SqlCeConnection(String.Format("{0}", strconnection))

I have added all the required assemblies and imported the needed namespaces.The cmd.ExecuteNonQuery() returns 1 which means there is no problem with the insert command.But when i try to view the data through server explorer, I get no rows inserted. Any help would be highly welcome.

¿Fue útil?

Solución

Ok, When you use SqlCe the database is a file that is added to your application output folder. You have a DataDirectory in the same folder of your solution. But if you look into the Debug folder you will see the .exe and another DataDirectory. The server explorer is connected to the solution folder, not the Debug folder, that's why you cant see the new row

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top