8 Replies - 1799 Views - Last Post: 18 April 2011 - 06:49 AM

#1 Snipe31  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 17-April 11

No error msg in debug but cannot update SQLCE Dbase in VB.net

Posted 17 April 2011 - 11:02 PM

Hi Experts,

I'm making a small application with windows mobile 6.5 using Visual Studio 2008 vb.net and SQLCE 3.51
i try to update the table name "UserSet" when i run the application for testing in my desktop i found No error
but when i look on the table there's no changes

Here is my Code


    Public Function App_Path() As String
        'return the application path
        Return System.IO.Path.GetDirectoryName( _
            System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
    End Function


    Private Sub CmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdOK.Click
        Dim data_base As String = "\\sqlSA1.sdf"
        Dim ConnString As String = "Data Source=" & App_Path() & data_base

        Try
            Me.TextBox1.Text = App_Path() & data_base


            Dim conn As SqlCeConnection = New SqlCeConnection(ConnString)
            conn.Open()

            Dim cmd As SqlCeCommand = conn.CreateCommand

        

            cmd.CommandText = "Update UserSet set UserLogin = @Status where UserName = @UserName and UserPassword = @Password"

           
            Dim Stat As SqlCeParameter
            Dim UserN As SqlCeParameter
            Dim PassW As SqlCeParameter
          
            Stat = cmd.Parameters.Add("Status", SqlDbType.NVarChar)
            UserN = cmd.Parameters.Add("UserName", SqlDbType.NVarChar)
            PassW = cmd.Parameters.Add("Password", SqlDbType.NVarChar)
            Stat.Value = "Y"
            UserN.Value = Me.Text_UserName.Text
            PassW.Value = Me.Text_Password.Text

            cmd.ExecuteNonQuery()
            MsgBox("record updated")
            conn.Close()

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
   


Thank you in advance

Is This A Good Question/Topic? 0
  • +

Replies To: No error msg in debug but cannot update SQLCE Dbase in VB.net

#2 Vishu Sukhdev  Icon User is offline

  • D.I.C Head

Reputation: 38
  • View blog
  • Posts: 150
  • Joined: 19-February 10

Re: No error msg in debug but cannot update SQLCE Dbase in VB.net

Posted 17 April 2011 - 11:18 PM

View PostSnipe31, on 18 April 2011 - 06:02 AM, said:

  
            Stat = cmd.Parameters.Add("Status", SqlDbType.NVarChar)
            UserN = cmd.Parameters.Add("UserName", SqlDbType.NVarChar)
            PassW = cmd.Parameters.Add("Password", SqlDbType.NVarChar)

    


Hi,
I haven't worked on Windows Mobile Application yet but after seeing your code i think you never set parameters.
try this
            Stat = cmd.Parameters.Add("@Status", SqlDbType.NVarChar)
            UserN = cmd.Parameters.Add("@UserName", SqlDbType.NVarChar)
            PassW = cmd.Parameters.Add("@Password", SqlDbType.NVarChar)


Was This Post Helpful? 1
  • +
  • -

#3 Atli  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3053
  • View blog
  • Posts: 4,575
  • Joined: 08-June 10

Re: No error msg in debug but cannot update SQLCE Dbase in VB.net

Posted 17 April 2011 - 11:23 PM

Hey.

Not knowing the first thing about Windows mobile, nor a lot of in-depth details about VB.NET, there are two things there that I'd point out.

First, the ExecuteNonQuery() returns the number of affected rows, does it not? You should capture that return value and check to see if there was anything updated, rather than just assume that it was. Even if the SQL query executes without error, it is possible that it didn't actually update any rows.

Second, should the first parameter of the cmd.Parameters.Add call not include the @ char you use in the SQL query? That is at least how the SQL Server and MySQL versions of this class do it :)

This post has been edited by Atli: 17 April 2011 - 11:25 PM

Was This Post Helpful? 1
  • +
  • -

#4 Snipe31  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 17-April 11

Re: No error msg in debug but cannot update SQLCE Dbase in VB.net

Posted 17 April 2011 - 11:31 PM

Hi Experts thanks for a very fast reply

I have try to put @ on the cmd.parameter.add but still same result

thanks again
Was This Post Helpful? 0
  • +
  • -

#5 Snipe31  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 17-April 11

Re: No error msg in debug but cannot update SQLCE Dbase in VB.net

Posted 17 April 2011 - 11:44 PM

Hi again

I also add an integer to count the rows that is affected by the update
the Integer Increment but when i look directly on the table it doesn't change any thing

           dim Ra as integer
           Ra = ExecuteNonQuery()

           msgbox("Row Updated" & Ra)
        

thanks again
Was This Post Helpful? 0
  • +
  • -

#6 Vishu Sukhdev  Icon User is offline

  • D.I.C Head

Reputation: 38
  • View blog
  • Posts: 150
  • Joined: 19-February 10

Re: No error msg in debug but cannot update SQLCE Dbase in VB.net

Posted 18 April 2011 - 12:21 AM

View PostSnipe31, on 18 April 2011 - 06:44 AM, said:

I also add an integer to count the rows that is affected by the update
the Integer Increment but when i look directly on the table it doesn't change any thing


I Think You Should Refresh Table To See Change Values
Was This Post Helpful? 0
  • +
  • -

#7 Snipe31  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 17-April 11

Re: No error msg in debug but cannot update SQLCE Dbase in VB.net

Posted 18 April 2011 - 01:01 AM

Hi Experts
I already try to refresh the table but still same result. I try to experiment and transfer the same code to a windows application and got the result the database is update. I guess i have to change my approach in windows mobile development it seems that the database path is change in run time and i'm looking on a different table. I really dont get how the windows mobile 6.5 emulator work and behave any way thanks alot for the help really appreciate it.



Thanks Again
Was This Post Helpful? 0
  • +
  • -

#8 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1511
  • View blog
  • Posts: 5,916
  • Joined: 21-March 08

Re: No error msg in debug but cannot update SQLCE Dbase in VB.net

Posted 18 April 2011 - 04:47 AM

If you have the option, test on a physical device. I've never liked the emulator for Windows Mobile.
Was This Post Helpful? 0
  • +
  • -

#9 Snipe31  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 17-April 11

Re: No error msg in debug but cannot update SQLCE Dbase in VB.net

Posted 18 April 2011 - 06:49 AM

Hi Experts

I added addional function on my mobile application device to check if the table is updated
I Update the table (as i wanted to do) then add a grid and Query the same parameters and bind it
to datagrid to view the result of the table. I found out that the table is updated base on my Query
I guess windows mobile emulator create a copy of my sdf in the root folder of the emulator
and update it not the one that i have attach in my database solution page, that why (I guess)
I cannot see any update from my database solution page
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1