I'm using visual basic 2008 express edition by linq to sql for my database operation such as edit records. I did not use any sql server but I'm just using the built-in sql server within the visual basic 2008 express. I tried to revised the codes, no error in syntax but there's an error at runtime and it pops-up a window message saying its error message. What I want is to edit the records which were retrieved from the database into the text-boxes and when you click the button5 whatever the new value on the text-boxes should replace the previous one. The Account field is the field in my Table1 in memrec.dbml which I set up for primary key is true and the rest of the fields are false in its primary key. The code below still found an error when you run the program and it pops-up a window which says:
NotSupportedException was unhandled - Sql server does not handle comparison of NText, Text, Xml, or Image data types.
It highlights a yellow background on the line:
db.SubmitChanges()
These are what I see on each field's property on Table1 in memrec.dbml property window:
Access - Public
Type - String(System.String)
Server Data Type - Text
Auto-Generated Value - False
Auto-Sync - Never
Delay Loaded - False
Inheritance Modifier - (none)
Nullable - True
Read Only - False
Time Stamp - False
Update Check - Never
Primary Key - False ' Except for the Account field.
What do you see as possible error?
Is it in terms of its settings?
Here's my codes:
Private Sub Button5_Click(------------------) Handles Button5.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or _
TextBox4.Text = "" Then
MsgBox("Please Fill It Up Completely", MsgBoxStyle.Exclamation)
Exit Sub
Else
Dim accnt As String
accnt = TextBox1.Text
Dim db As New memrecDataContext()
Dim editrecord = _
From memrec In db.Table1s _
Where memrec.Account.Contains(accnt) _
Select memrec
For Each memrec In editrecord
If memrec.Account = accnt Then
memrec.Account = TextBox1.Text
memrec.Name = TextBox2.Text
memrec.Address = TextBox3.Text
memrec.Gender = TextBox4.Text
db.SubmitChanges()
Exit Sub
End If
Exit For
Next
MsgBox("No Records Match", MsgBoxStyle.Information)
End If
End Sub
Thank you for taking time with me to solve this issue.....
This code will perform a "like" in your database and such action is not permited on
NText
andText
field.Try changing your field type from
Text
toVarchar(500)
(or bigger if you think 500 won't be enough)or
If you intended to search for a known value, try changing you where to :
The code is a little hard to read, but from what I could understand, it should work. You just need to put the SubmitChanges() method invocation outside the for loop.
Imports System.Data Imports System.Data.SqlClient
Public Class frmRpro
err: Exit Sub End Sub
End Class