Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > SQL Connexion problem...

Reply
Thread Tools

SQL Connexion problem...

 
 
+The_Taco+
Guest
Posts: n/a
 
      10-17-2003
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!


 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      10-17-2003
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+" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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!
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux/Python -> SQL*Server Connexion chain Gilles Lenfant Python 1 09-22-2005 06:01 PM
Unique user connexion to a web site [ASP.NET 2] =?Utf-8?B?VGhvbWFzQg==?= ASP .Net 0 06-02-2005 08:28 AM
Wireless connexion very slow Michel S. Wireless Networking 3 05-30-2005 10:54 PM
connexion wifi intermitente Stephane T Wireless Networking 1 05-25-2005 08:20 PM
Wireless connexion problem.. Michel S. Wireless Networking 2 05-21-2005 09:32 PM



Advertisments