SQL Connexion problem...

Discussion in 'ASP .Net' started by +The_Taco+, Oct 17, 2003.

  1. +The_Taco+

    +The_Taco+ Guest

    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!
    +The_Taco+, Oct 17, 2003
    #1
    1. Advertising

  2. 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+" <> wrote in message
    news:...
    > 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!
    >
    >
    Kevin Spencer, Oct 17, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VGhvbWFzQg==?=

    Unique user connexion to a web site [ASP.NET 2]

    =?Utf-8?B?VGhvbWFzQg==?=, Jun 2, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    470
    =?Utf-8?B?VGhvbWFzQg==?=
    Jun 2, 2005
  2. eldie

    database connexion check

    eldie, Jun 9, 2006, in forum: Java
    Replies:
    5
    Views:
    357
    shakah
    Jun 14, 2006
  3. Gilles Lenfant

    Linux/Python -> SQL*Server Connexion chain

    Gilles Lenfant, Sep 22, 2005, in forum: Python
    Replies:
    1
    Views:
    350
    Benji York
    Sep 22, 2005
  4. Beckam
    Replies:
    4
    Views:
    351
    Neil Coffey
    Jun 3, 2008
  5. Replies:
    0
    Views:
    87
Loading...

Share This Page