SQL Server Parameter transfer

AadKabel

New Member
Joined
Oct 3, 2018
Messages
3
I am trying to update a record at SQL Server by using parameters.
The VBA-code does not initiate an error, but the files at SQL Server Table are not updatet with worksheet data.
Can anybody see what I am doing wrong?


Description = Range("E42").Value
Mitigation = Range("E51").Value
Supervision = Range("E60").Value

Dim cmd As New ADODB.Command
Dim conn As ADODB.Connection
Dim prm As ADODB.Parameter
Dim strConn As String

'Developping
Server_Name = "localhost"
Database_Name = "AIM"

strConn = "Provider=SQLNCLI11;" & "Server=" & Server_Name & _
";Database=" & Database_Name & _
";Integrated Security=SSPI;"

Set conn = New ADODB.Connection
conn.Open strConn
Set cmd = New ADODB.Command
cmd.CommandText = "UPDATE dram.Register " & _
"SET Description = Description, " & _
"Mitigation = Mitigation, " & _
"Supervision = Supervision " & _
"WHERE DRAM_ID = DRAM_ID"
cmd.CommandType = adCmdText
cmd.ActiveConnection = conn

Set prm = cmd.CreateParameter("DRAM_ID", adVarChar, adParamInput, 255, CaseId)
cmd.Parameters.Append prm

Set prm = cmd.CreateParameter("Description", adVarChar, adParamInput, 255, Description)
cmd.Parameters.Append prm

Set prm = cmd.CreateParameter("Mitigation", adVarChar, adParamInput, 255, Mitigation)
cmd.Parameters.Append prm

Set prm = cmd.CreateParameter("Supervision", adVarChar, adParamInput, 255, Supervision)
cmd.Parameters.Append prm

cmd.Execute
conn.Close

Thanks.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Have you tried manually running the query in SSMS or using some other method?

Does it work if you hard-code values rather than use parameters?
 
Upvote 0
Thanks for your response.

Hard-code values remains equal as by using variables.

i haven't manually the query in SSMS and don't know how to do. Looked at it, but can't find it.
Do you have some guidance?
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top