Hi there ,


Just wondering if anyopne could help me out with a problem I am having with a update statement.


I this error


ExecuteNonQuery: Connection property has not been initialized.
I have been at this all day and still can't figure the problem.
Hope someone can put a light on the matter .


thanks
Here the code I am using

Try
            Connection_Update = New OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0;Data Source = KellihersLawnmowers.accdb")
            OleCommand_Update = New OleDbCommand("Update tblRatings(Vat_Rate_New,Vat_Rate_Second,Labour_per_hour)Set" & _
            " Vat_Rate_New = " & VatUser & _
            " ,Labour_per_hour= " & HourUser & _
            " ,Vat_Rate_Second = " & Vat2User & _
            " ,Discount = " & DiscountUser & _
             " WHERE ID = " & 1)
           
            Connection_Update.Open()
            OleCommand_Update.ExecuteNonQuery()



        Catch myException As Exception
            MsgBox(myException.Message)


        Finally

            Connection_Update.Close()
            cnn.Close()

        End Try

Thanks again .
Any help would really be appreciated.

James

How about if you add this statement in your code

Dim conn As New OleDb.OleDbConnection
Dim comm As New OleDb.OleDbCommand

thanks
Here the code I am using

Try
'' Add this statement
Dim Connection_Update As New OleDb.OleDbConnection
Dim OleCommand_Update As New OleDb.OleDbCommand

            Connection_Update = New OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0;Data Source = KellihersLawnmowers.accdb")
            OleCommand_Update = New OleDbCommand("Update tblRatings(Vat_Rate_New,Vat_Rate_Second,Labour_per_hour)Set" & _
            " Vat_Rate_New = " & VatUser & _
            " ,Labour_per_hour= " & HourUser & _
            " ,Vat_Rate_Second = " & Vat2User & _
            " ,Discount = " & DiscountUser & _
             " WHERE ID = " & 1)

Initialize a Connection property of command object.

...
OleCommand_Update.Connection=Connection_Update             
Connection_Update.Open()
OleCommand_Update.ExecuteNonQuery()
.....

I have Declared them at module Level already.
Thanks for the Input

How about if you add this statement in your code

Dim conn As New OleDb.OleDbConnection
Dim comm As New OleDb.OleDbCommand

thanks
Here the code I am using

Try
'' Add this statement
Dim Connection_Update As New OleDb.OleDbConnection
Dim OleCommand_Update As New OleDb.OleDbCommand

            Connection_Update = New OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0;Data Source = KellihersLawnmowers.accdb")
            OleCommand_Update = New OleDbCommand("Update tblRatings(Vat_Rate_New,Vat_Rate_Second,Labour_per_hour)Set" & _
            " Vat_Rate_New = " & VatUser & _
            " ,Labour_per_hour= " & HourUser & _
            " ,Vat_Rate_Second = " & Vat2User & _
            " ,Discount = " & DiscountUser & _
             " WHERE ID = " & 1)

Initialize a Connection property of command object.

...
OleCommand_Update.Connection=Connection_Update             
Connection_Update.Open()
OleCommand_Update.ExecuteNonQuery()
.....

thanks very much that did the trick. But know I get a error with
Syntax error in UPDATE statement.

I found one proble with the statement whereby I left out discount but that still doesn't solve the problem.

Can anyone spot what is wrong with the String?

OleCommand_Update = New OleDbCommand("Update tblRatings(Vat_Rate_New,Vat_Rate_Second,Labour_per_hour,Discount)Set" & " Vat_Rate_New=" & VatUser & ",Vat_Rate_Second=" & HourUser & ",Labour_per_hour=" & Vat2User & ",Discount=" & DiscountUser & " WHERE ID =" & 1)

And by the way is all one one line in the program

Thanks again

James

Hi

Try this

Dim conn As New SqlClient.SqlConnection()
Dim cmd As New SqlClient.SqlCommand()
conn.ConnectionString = "Data Source=(local);Initial Catalog=myDatabase;Integrated Security=SSPI"
conn.Open()
conn.close()

Thanks,
Paul daniel

Hi

Try this

Dim conn As New SqlClient.SqlConnection()
Dim cmd As New SqlClient.SqlCommand()
conn.ConnectionString = "Data Source=(local);Initial Catalog=myDatabase;Integrated Security=SSPI"
conn.Open()
conn.close()

Thanks,
Paul daniel

Yeah I tried this but still the same result any other Ideas?

Thanks

James

Hey all,

I figured out what was wrong vb.net was telling me the hold time it was syntax error.


Thanks for all your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.