Question SQL Server CE throws exception while inserting data using code

Priyabrata

New member
Joined
Oct 15, 2013
Messages
1
Programming Experience
3-5
I am writing a code for a project and I am stuck in a place where it throws an exception, and this is my first project working with DB with VB.NET
VB.NET:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim connStr As New SqlCeConnection("Data Source=c:\users\babi\documents\visual studio 2012\Projects\ShopManager\ShopManager\" & "ManagementDB.sdf; Password =")
        Dim name, pass, repass As String
        name = TextBox1.Text
        If (name.Length = 0) Then
            MessageBox.Show("Enter user-name!!")
            Exit Sub
        End If
        pass = TextBox2.Text
        If (pass.Length = 0) Then
            MessageBox.Show("Enter password!!")
            Exit Sub
        End If
        repass = TextBox3.Text
        If (repass.Length = 0) Then
            MessageBox.Show("Re-enter password!!")
            Exit Sub
        End If
        If (getMD5Hash(pass) = getMD5Hash(repass)) Then
            Dim cmd As New SqlCeCommand("INSERT INTO User(uname, upass)VALUES(" & name & "," & getMD5Hash(pass) & ");", connStr)
            connStr.Open()
            cmd.ExecuteNonQuery() REM Exception is thrown when this line is executed
            connStr.Close()
            MessageBox.Show("User Created!")
            Exit Sub
        Else
            MessageBox.Show("Passwords donot match!!")
            Exit Sub
        End If
    End Sub
Related Query :
VB.NET:
[COLOR=#800000]"INSERT INTO User(uname, upass)VALUES(abcd,827ccb0eea8a706c4c34a16891f84e7b);"[/COLOR]
The exception that occurs is :
VB.NET:
[COLOR=#2B91AF]An[/COLOR] unhandled exception of type [COLOR=#800000]'System.Data.SqlServerCe.SqlCeException'[/COLOR] occurred [COLOR=#00008B]in[/COLOR] [COLOR=#2B91AF]System[/COLOR].[COLOR=#2B91AF]Data[/COLOR].[COLOR=#2B91AF]SqlServerCe[/COLOR].dll
I need urgent help with this issue..

I've attached the entire project and its written in VB.NET 2012

Regards
Priyabrata
 

Attachments

Last edited by a moderator:
Top Bottom