Je reçois cette erreur lorsque je débogue le code de mon site Web. Mon objectif est d'insérer des données dans la base de données SQL Server 2008.Erreur avec Visual Studio et SQL Server 2008
error Source:
objcnd.Parameters.Add(New SqlParameter("@username", strun))
Ligne 22 : objcnd.Parameters.Add(New SqlParameter("@password", strpw))
Ligne 23 : objcnd.ExecuteNonQuery()
Ligne 24 : 'close connection
Ligne 25 : objconnection.Close()
l'erreur
[SqlException (0x80131904): '?'. Syntaxe incorrecte près]
.....
System.Data.SqlClient.SqlConnection.OnError (exception SqlException , Boolean breakConnection) +2030802
System.Data.SqlClient.SqlInternalConnection.OnError (Exception SqlException, Boolean breakConnection) +5009584
System.D ata.SqlClient.TdsParser.ThrowExceptionAndWarning() +234
System.Data.SqlClient.TdsParser.Run (runBehavior RunBehavior, SqlCommand cmdHandler, SqlDataReader DATASTREAM, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) 2275
La source de code écrit dans vb.net
Imports System
Imports System.Data
Imports System.Data.SqlClient
Partial Class index
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strun As String = Request.Form("username")
Dim strpw As String = Request.Form("password")
Dim objconnection As SqlConnection = Nothing
Dim objcnd As SqlCommand = Nothing
Dim strconnection As String, strSQL As String
'connection string
strconnection = ("Data Source=myPC-PC;Database=mytempDB;Integrated Security=true ")
objconnection = New SqlConnection(strconnection)
objconnection.ConnectionString = strconnection
objconnection.Open()
strSQL = "insert into userTD(username,password) values(?,?)"
objcnd = New SqlCommand(strSQL, objconnection)
objcnd.Parameters.Add(New SqlParameter("@username", strun))
objcnd.Parameters.Add(New SqlParameter("@password", strpw))
objcnd.ExecuteNonQuery()
'close connection
objconnection.Close()
Response.Write("Entered Successfully ! ")
End Sub
End Class
Merci à l'avance.
Cela fonctionne :) merci beaucoup. – user2649088