User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 456,485 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,780 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser: Programming Forums
Views: 4781 | Replies: 8
Reply
Join Date: Sep 2007
Posts: 6
Reputation: SGiorgos is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
SGiorgos SGiorgos is offline Offline
Newbie Poster

Help DataSource on windows mobile 6 (cant connect to sqlce database file [sdf])

  #1  
Sep 13th, 2007
Hi,
I am currently developing an application using vb.net 2005 and windows mobile 6 sdk,and sql server ce for my database.

I try to connect to the database i created using the following code: I get an identifier expected error
pointing the dot[.] .The code is this ("Data Source =".\ MyDatabase.sdf;"")

Visual Basic.Net 2005. The whole class is the following:

Dim conn As SqlCeConnection = Nothing

Try
conn = New SqlCeConnection("Data Source =".\ MyDatabase.sdf;"")
conn.Open()

Dim cmd As SqlCeCommand = conn.CreateCommand()
cmd.CommandText = "INSERT INTO Customers (Customerid], Name) Values('9', 'Smith')"

cmd.ExecuteNonQuery()
Finally
conn.Close()
End Try
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2005
Posts: 85
Reputation: williamrojas78 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
williamrojas78's Avatar
williamrojas78 williamrojas78 is offline Offline
Junior Poster in Training

Re: DataSource on windows mobile 6 (cant connect to sqlce database file [sdf])

  #2  
Sep 13th, 2007
Hi

I think the problem is that the syntax of your command is wrong.
You have:

conn = New SqlCeConnection("Data Source =".\ MyDatabase.sdf;"")

it should be:
conn = New SqlCeConnection("Data Source =.\ MyDatabase.sdf")

I use this and it works.

    dim data_base As String = "\Program Files\My App\MyDB.sdf"

    dim dap As SqlCeDataAdapter = New SqlCeDataAdapter
    dim conn As SqlCeConnection = New SqlCeConnection("Data Source=" & data_base)
    dim cmnd As SqlCeCommand = New SqlCeCommand("SELECT FROM table", conn)

   conn.open()
   ...

Hope it helps
Reply With Quote  
Join Date: Sep 2007
Posts: 6
Reputation: SGiorgos is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
SGiorgos SGiorgos is offline Offline
Newbie Poster

Re: DataSource on windows mobile 6 (cant connect to sqlce database file [sdf])

  #3  
Sep 13th, 2007
"\Program Files\My App\MyDB.sdf"

is this relative to the windows mobile path(emulator) or the local computer path ?
Reply With Quote  
Join Date: Jun 2005
Posts: 85
Reputation: williamrojas78 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
williamrojas78's Avatar
williamrojas78 williamrojas78 is offline Offline
Junior Poster in Training

Re: DataSource on windows mobile 6 (cant connect to sqlce database file [sdf])

  #4  
Sep 14th, 2007
This is relative to the PPC (mobile device) path.
That is the location of the database in the PPC - I use the same directory as my application.
Reply With Quote  
Join Date: Sep 2007
Posts: 6
Reputation: SGiorgos is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
SGiorgos SGiorgos is offline Offline
Newbie Poster

Re: DataSource on windows mobile 6 (cant connect to sqlce database file [sdf])

  #5  
Sep 14th, 2007
Hi, Thank you . Now the path seems to work. The other problem is I cant add data to the database.

The code I use is:

        Dim MyConnection As SqlCeConnection
        Dim sqlstring As String = "INSERT INTO Titles VALUES ('2','1','0')"

        Dim data_base As String = "\Program Files\vbdata\vbdata.sdf"

        MyConnection = New SqlCeConnection("Data Source=" & data_base)

        Dim concom As SqlCeCommand = MyConnection.CreateCommand()

        Dim cmnd As SqlCeCommand = New SqlCeCommand(sqlstring, MyConnection)

        Dim myreader As SqlCeDataReader

        MyConnection.Open()

        myreader = cmnd.ExecuteReader


        MyConnection.Close()

Thanks again.
Last edited by SGiorgos : Sep 14th, 2007 at 1:34 pm. Reason: edit to reveal code
Reply With Quote  
Join Date: Jun 2005
Posts: 85
Reputation: williamrojas78 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
williamrojas78's Avatar
williamrojas78 williamrojas78 is offline Offline
Junior Poster in Training

Re: DataSource on windows mobile 6 (cant connect to sqlce database file [sdf])

  #6  
Sep 14th, 2007
Hi
your code is not executing the command (i think); try this:

        Dim MyConnection As SqlCeConnection
        Dim sqlstring As String = "INSERT INTO Titles VALUES ('2','1','0')"

        Dim data_base As String = "\Program Files\vbdata\vbdata.sdf"

        MyConnection = New SqlCeConnection("Data Source=" & data_base)

        Dim concom As SqlCeCommand = MyConnection.CreateCommand()

        MyConnection.Open()        
        Dim cmnd As SqlCeCommand = New SqlCeCommand(sqlstring, MyConnection)
        
        cmnd.ExecuteNonQuery()        ' Execute the command here

        'and then read
        Dim myreader As SqlCeDataReader
 
        myreader = cmnd.ExecuteReader

        MyConnection.Close()
Reply With Quote  
Join Date: Sep 2007
Posts: 6
Reputation: SGiorgos is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
SGiorgos SGiorgos is offline Offline
Newbie Poster

Re: DataSource on windows mobile 6 (cant connect to sqlce database file [sdf])

  #7  
Sep 17th, 2007
hi,
I have also tried the code you provided with no luck again :/
Reply With Quote  
Join Date: Jun 2005
Posts: 85
Reputation: williamrojas78 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
williamrojas78's Avatar
williamrojas78 williamrojas78 is offline Offline
Junior Poster in Training

Re: DataSource on windows mobile 6 (cant connect to sqlce database file [sdf])

  #8  
Sep 17th, 2007
Hi

I just noticed that you are missing the field names in the sql command, you have:
Dim sqlstring As String = "INSERT INTO Titles VALUES ('2','1','0')"
and it should be:
Dim sqlstring As String = "INSERT INTO Titles(fileld0, field1, field2)  VALUES ('2','1','0')"

I just tried it on my PPC and it works. I also noticed that you the command specifies all the values as strings, but they are numbers. Make sure you input the values in the right format, otherwise you might have an error.
Reply With Quote  
Join Date: Sep 2007
Posts: 6
Reputation: SGiorgos is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
SGiorgos SGiorgos is offline Offline
Newbie Poster

Re: DataSource on windows mobile 6 (cant connect to sqlce database file [sdf])

  #9  
Sep 17th, 2007
thnx a lot, everything is working like a charm

The net thing now is how to query the emulators database :p ( i mean through visual basic query manager ) . Because when i insert data through the emulator and then close the emulator the database is not stored anywhere .

thnx again
Last edited by SGiorgos : Sep 17th, 2007 at 3:15 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb VB.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the VB.NET Forum

All times are GMT -4. The time now is 3:03 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC