75THRGR
asked on
Visual Studio SqlCeConnection for Smart Device: SDF opening problem
I am a student trying to integrate a database into a smart device project using Visual Studio 2008. I want to run some SQL queries when a form loads to populate a combo box, and I think I have the code to open a database as a SqlCeConnection, but must be missing something. When i open the form, it tells me that "The database file cannot be found".
I'm pretty sure I have the SDF file embedded in the project (its new to me, so i might be looking at it wrong). Can't understand why it's unable to find the database. My ultimate goal is to populate the combo box as a first step; What am i doing wrong here?
I'm pretty sure I have the SDF file embedded in the project (its new to me, so i might be looking at it wrong). Can't understand why it's unable to find the database. My ultimate goal is to populate the combo box as a first step; What am i doing wrong here?
Private Sub frmItemSelect_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strSql As String = "SELECT [BAR_CODE] FROM INVENTORY WHERE [USER_ID] = 12345"
Dim strPath As String = "Data Source=AppDatabase1.sdf;Persist Security Info=False;"
Dim sconInventory As New SqlCeConnection(strPath)
Dim scmdInventory As New SqlCeCommand(strSql, sconInventory)
Dim val1 As Integer()
sconInventory.Open() 'This is the line telling me it can't find the database. Everything below is code I'll fix later
Dim sqlReader As SqlCeDataReader = scmdInventory.ExecuteReader()
Try
Dim i As Integer = 0
While sqlReader.Read()
val1(i) = sqlReader.GetInt32(0)
i += 1
MsgBox(val1(i) & " " & i)
End While
Finally
sqlReader.Close()
sconInventory.Close()
End Try
For i = 0 To val1.length - 1
Next
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER