mhlaskar1991
mhlaskar1991

Reputation: 71

connection.execute

`Dim con1 As New ADODB.Connection
Dim rs1 As New ADODB.Recordset
Dim sql1 As String
sql1 = "Update Balance set Balance_Amt = (Balance_Amt + " & a & ") where Company = " & Combo3.Text
con1.Execute (sql1)

"Can anyone say why this code does not work? It says No value for one or more required parameters"

Upvotes: 0

Views: 136

Answers (2)

Ferruccio
Ferruccio

Reputation: 100748

I would guess that the immediate problem is that the SQL fragment

where Company = value

is invalid SQL. It should be quoted:

where Company = 'value'

But you really should be using SQL parameters.

  1. I would have avoided this issue since the parameter would have been automatically quoted as necessary.
  2. It would have made the code easier to read.
  3. It would not be susceptible to SQL Injection attacks.

e.g.

Using cmd = new SqlCommand("UPDATE Balance SET Balance_Amt = (Balance_Amt + @a) WHERE Company=@company", con1)
    cmd.Parameters.AddWithValue("@a", a)
    cmd.Parameters.AddWithValue("@company", company)
    cmd.ExecuteNonQuery()
End Using

Upvotes: 1

Anders Lindén
Anders Lindén

Reputation: 7322

Print out the sql statement and see if it is ok, copy/paste it to the sql management studio. I think you are missing apostrophes around the string Combo3.Text.

Also consider what sql it would result in if Combo3.Text contains

'a'; delete from Balance

Upvotes: 0

Related Questions