I need some help at inserting my data (username and password) into a mssql database. with linq to sql this is my solution but at the -> marked line I always get an EntityCommandExecutionException. I have a html website with two textboxes where I get the String out of and send the request via javascript - ajax to vb.net.
I'm doing research now for a long time and i can't find any solution.
As you can see I want to check if there is a datarow with this username but it doesn't work in the situation when there is no datarow in the table. That means the query should be 'NULL' or am I wrong?
Public Shared Function addData(ByVal username As String, ByVal passwort As String)
Dim db = New LoginContext
Dim benutzer = New Benutzer
Dim available As Boolean = False
Dim sha As New SHA1CryptoServiceProvider
Dim vName = (_
From b In db.BenutzerSet
Where b.Name = username.ToLower()
Select b)
-> If vName.Count() = 0 Or vName Is Nothing Then
benutzer.Name = username.ToLower()
Dim bytesToHash() As Byte
bytesToHash = System.Text.Encoding.ASCII.GetBytes(passwort)
bytesToHash = sha.ComputeHash(bytesToHash)
Dim encPassword As String = ""
For Each b As Byte In bytesToHash
encPassword += b.ToString("x2")
Next
benutzer.Passwort = encPassword
db.BenutzerSet.Add(benutzer)
db.SaveChanges()
available = True
Else
available = False
End If
Return available
End Function
Thanks for your help.