ExecuteScalar: Connection property has not been initialized.

Discussion in 'ASP.NET / ASP.NET Core' started by lukesb, Nov 5, 2009.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Hi

    I get ExecuteScalar: Connection property has not been initialized. on dbCMD2.ExecuteScalar() of the following

    Dim dbconn2 As SqlConnection
    Dim dbCMD2 As SqlCommand

    dbconn2 = New SqlConnection("Data Source=tcp:esql2k801.discountasp.net;Initial Catalog=SQL2008_678810_aspnetdb;User ID=*******;Password=*******;")
    dbconn2.Open()
    dbCMD2 = New SqlCommand("INSERT INTO ReturnValue Values " & GridView1.Rows(0).Cells(0).Text.ToString & ", " & GridView1.Rows(0).Cells(1).Text.ToString & ", " & GridView1.Rows(0).Cells(2).Text.ToString & ", " & GridView1.Rows(0).Cells(3).Text.ToString & ", " & GridView1.Rows(0).Cells(4).Text.ToString & ", " & GridView1.Rows(0).Cells(5).Text.ToString & ", " & GridView1.Rows(0).Cells(6).Text.ToString & ", " & GridView1.Rows(0).Cells(7).Text.ToString & ", " & GridView1.Rows(0).Cells(8).Text.ToString & ", " & GridView1.Rows(0).Cells(9).Text.ToString & ", " & GridView1.Rows(0).Cells(10).Text.ToString & ", " & GridView1.Rows(0).Cells(11).Text.ToString & ", " & GridView1.Rows(0).Cells(12).Text.ToString & ", " & GridView1.Rows(0).Cells(13).Text.ToString & ", " & GridView1.Rows(0).Cells(14).Text.ToString & ", " & GridView1.Rows(0).Cells(15).Text.ToString & ", " & GridView1.Rows(0).Cells(16).Text.ToString & ", " & GridView1.Rows(0).Cells(17).Text.ToString & ", " & GridView1.Rows(0).Cells(18).Text.ToString & ", " & GridView1.Rows(0).Cells(19).Text.ToString & ", " & GridView1.Rows(0).Cells(20).Text.ToString & ", " & GridView1.Rows(0).Cells(21).Text.ToString & ", " & GridView1.Rows(0).Cells(22).Text.ToString & ", " & GridView1.Rows(0).Cells(23).Text.ToString & ", " & GridView1.Rows(0).Cells(24).Text.ToString & ", " & GridView1.Rows(0).Cells(25).Text.ToString & ", " & GridView1.Rows(0).Cells(26).Text.ToString & ", " & GridView1.Rows(0).Cells(27).Text.ToString & ", " & GridView1.Rows(0).Cells(28).Text.ToString & ", " & GridView1.Rows(0).Cells(29).Text.ToString & ", " & GridView1.Rows(0).Cells(30).Text.ToString & ", " & GridView1.Rows(0).Cells(31).Text.ToString & ", " & GridView1.Rows(0).Cells(32).Text.ToString & ", " & Now & ", " & User.Identity.Name)
    dbCMD.Connection = dbconn2

    dbCMD2.ExecuteScalar()
    dbconn2.Close()

    Can someone help with this..?

    Cheers

    Luke
     
  2. Hi,
    Two thoughts...
    1) I believe it will fail if the record is locked.
    2) Shouldn't that be returned as an instance value?
    i.e.
    Dim MyReturnedValue As Object
    ...
    MyReturnedValue = dbCMD2.ExecuteScalar()

    note: I haven't been using this for a bit and am rusty. ;-)
    All the best,
    Mark
     
  3. Hi Mark

    I just got it working. I added

    dbCMD2.Connection = dbconn2

    Just before

    dbCMD2.ExecuteScalar()

    I think it's becasue I forgot to put

    ,dbConn2

    at the end of my SQL maybe...

    Cheers

    Luke
     
  4. Awesome..Thanks for the re-post. ;-)
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page