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! 1 999
You never instantiated the Command object.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer http://www.takempis.com
Big Things are made up of
Lots of Little Things.
"+The_Taco+" <do***********@dessausoprin.com> wrote in message
news:e1**************@TK2MSFTNGP09.phx.gbl... 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!
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: cyril |
last post by:
Bonjour à tous, j'utilise Apache php et mysql sans probleme, j'ai
voulu passer pour des raisons pro sur IIS PHP MS SQL.IIS et PHP
fonctionne bien, j ai decommenté la ligne pour ms sql, copier la...
|
by: José |
last post by:
I have a farm with 4 web servers.
I want to write a client-server program to rotate logs.
Basically the server has only one file, if I run it, the server listens.
The client has 2 files, one...
|
by: elsC |
last post by:
Bonjour,
Je viens d'installer SQL Server 2000 Dev edition.
J'ai créé des connexions sécurisées SQL Server et pourtant lorsque
j'essaie de me connecter avec PHP (mssql_connect('localhost',...
|
by: Peter Olcott |
last post by:
www.halting-problem.com
|
by: Jon Davis |
last post by:
If I have a class with a virtual method, and a child class that overrides
the virtual method, and then I create an instance of the child class AS A
base class...
BaseClass bc = new ChildClass();...
|
by: Ammar |
last post by:
Dear All,
I'm facing a small problem.
I have a portal web site, that contains articles, for each article, the end
user can send a comment about the article.
The problem is:
I the comment length...
|
by: ThomasB |
last post by:
hello all, and first sorry for my bad english.
I'm trying to implement a way to enable unique connexion for user to a web
site with VWExpress, dotnet 2.
I use profile to store user...
|
by: Serge Fournier |
last post by:
Hello everyone.
How to give the connexion information to a crystal report at run time ?
same question concerning the SQL string for data extraction ?
Is it "a must" to disconnect the report at...
|
by: Secrétariat |
last post by:
Hello !
I use a PostgreSQL server 7.4 on Linux Mandrake 10 with IP 192.168.0.15,
a database gestix is created.
An PostegreSQL user "postgres" id defined on this server,
I add in the...
|
by: tsic |
last post by:
Bonjour,
Voilà, j'ai débuté recemment avec python et je veux faire une connexion client serveur (windows) par l'intermédiaire d'une interface QT Designer v 4. j'ai choisi ERIC v 4 comme IDE.
...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |