T
+The_Taco+
Im trying to insert only one row in my database with the SQLClient class.
But I get this error: "Object reference not set to an instance of an
object". Can anyone tell me why I get this error? Here's my code:
Dim cnn As New SqlClient.SqlConnection
Dim cmd As SqlClient.SqlCommand
Dim strNomServeur As String
Dim strNomDatabase As String
Dim strUserID As String
Dim strUserPWD As String
Dim strRequete As String
strNomServeur = "STAT-1-038"
strNomDatabase = "StockageErreur"
strUserID = "ferodo"
strUserPWD = "taco2000"
strRequete = "INSERT INTO StockageErreur(NomEntrant, NomApplication,
DescriptionErreur, DateEntree, DateRappel, Critique, DateRegle)" & _
"VALUES ('test', 'test', 'test encore', '02/02/02', '02/02/02', 'est',
'02/02/02')"
cnn.ConnectionString = "Data Source=" & strNomServeur & "; Initial Catalog="
& strNomDatabase & "; User ID=" & strUserID & "; Password=" & strUserPWD &
"; "
cnn.Open()
cmd.Connection = cnn '<------- I get the error right here
cmd.CommandText = strRequete
cmd.ExecuteNonQuery()
cmd.Connection.Close()
thx for the help guys!
But I get this error: "Object reference not set to an instance of an
object". Can anyone tell me why I get this error? Here's my code:
Dim cnn As New SqlClient.SqlConnection
Dim cmd As SqlClient.SqlCommand
Dim strNomServeur As String
Dim strNomDatabase As String
Dim strUserID As String
Dim strUserPWD As String
Dim strRequete As String
strNomServeur = "STAT-1-038"
strNomDatabase = "StockageErreur"
strUserID = "ferodo"
strUserPWD = "taco2000"
strRequete = "INSERT INTO StockageErreur(NomEntrant, NomApplication,
DescriptionErreur, DateEntree, DateRappel, Critique, DateRegle)" & _
"VALUES ('test', 'test', 'test encore', '02/02/02', '02/02/02', 'est',
'02/02/02')"
cnn.ConnectionString = "Data Source=" & strNomServeur & "; Initial Catalog="
& strNomDatabase & "; User ID=" & strUserID & "; Password=" & strUserPWD &
"; "
cnn.Open()
cmd.Connection = cnn '<------- I get the error right here
cmd.CommandText = strRequete
cmd.ExecuteNonQuery()
cmd.Connection.Close()
thx for the help guys!