Note that there are some explanatory texts on larger screens.

plurals
  1. POSQLCe Database in VB.NET Throws Exception while inserting data in table
    primarykey
    data
    text
    <p>I am playing with databases and today in my attempt to work with SQLCompactEdition database, I've created a local database named UserDB and have a table in it named, User.</p> <p>I've logged in into admin using my app(which is another database) and through admin, I am creating a user.</p> <p>Code I used for the purpose is : </p> <pre><code>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\ShopManagement\ShopManagement\" &amp; "User\UserDB.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(" &amp; name &amp; "," &amp; getMD5Hash(pass) &amp; ");", connStr) connStr.Open() cmd.ExecuteNonQuery() connStr.Close() MessageBox.Show("User Created!") Exit Sub Else MessageBox.Show("Passwords donot match!!") Exit Sub End If End Sub </code></pre> <p>When I debug, I find the querystring to be :</p> <pre><code>"INSERT INTO User(uname, upass)VALUES(abcd,827ccb0eea8a706c4c34a16891f84e7b);" </code></pre> <p>The Exception that occurs is :</p> <pre><code>An unhandled exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in System.Data.SqlServerCe.dll </code></pre> <p>I cannot understand what is causing this error. If any more information is required, please ask.</p> <p><em>EDIT</em></p> <p>Fixed Code :</p> <pre><code>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\" &amp; "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('" &amp; name &amp; "','" &amp; getMD5Hash(pass) &amp; "');", connStr) connStr.Open() cmd.ExecuteNonQuery() connStr.Close() MessageBox.Show("User Created!") Exit Sub Else MessageBox.Show("Passwords donot match!!") Exit Sub End If End Sub </code></pre> <p>The solution to the problem is given by the combination of the two solutions! So thank you to both of you :)</p> <p>Regards Priyabrata</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload