I encounter this particular error.
Exception Details:System.Data.SqlClient.SqlException: The data types varchar and text are incompatible in the equal to operator.
Line 21: Dim reader As SqlDataReader = command.ExecuteReader()
This is the first time I'm trying out with MS SQL so I'm abit lost. I hope my code is correct and I've did a little search. I did not set "Text" in my database, I use int and varchar. Here's the affected part of my code and the database.
Dim passwordAs String =""Dim querystringAs String ="SELECT Password FROM Member WHERE Username = @.username"'Dim conn as SqlConnection Using connAs New SqlConnection(ConfigurationManager.ConnectionStrings("mainconnect").ConnectionString)Dim commandAs New SqlCommand(querystring, conn) command.Parameters.Add("@.username", SqlDbType.Text) command.Parameters("@.username").Value = txtLogin.Text conn.Open()Dim readerAs SqlDataReader = command.ExecuteReader()While reader.Read() password = reader("Password").ToString()End While reader.Close()End Using
My database:
User_ID int(4)
Username varchar(50)
Password varchar(255)
Email varchar(50)
Any ideas?
Hi,
line
command.Parameters.Add("@.username", SqlDbType.Text)
should be
command.Parameters.Add("@.username", SqlDbType.VarChar,50)
argh! stupid me.. I forgot about that cause I've been working with MS Access.. Thanks it works!
No comments:
Post a Comment