[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Why don't my params populate ?

Posted on 2014-02-20
6
Medium Priority
?
243 Views
Last Modified: 2014-02-21
Trying to get an update with param to work, trying to populate a field with a string of text about 1k.  I don't get an error,  fields just don't populate.


            Dim cmd As New OleDb.OleDbCommand

            'VarChar DECLARE @msg VarChar 
            'cmd.Parameters.AddWithValue("@msg", Msg)

            '**** This works, but I don't want to worrry about ' and "
            'cmd.CommandText = _
            '    "DECLARE @msg VarChar " & _
            '    "UPDATE tblMsgs01 " & _
            '    "SET msg = '" & Msg & "' " & _
            '    "WHERE id = '" & sID & "'"

            '**** this does not work and I have to 'DECLARE @msg ...' or the SQL conn complains, ("You must declare scaler variable ...")
            cmd.CommandText = _
                 "DECLARE @msg VarChar " & _
                 "UPDATE tblMsgs01 " & _
                 "SET msg = @msg " & _
                 "WHERE id = '" & sID & "'"

            '*** Try 1, failed
            cmd.Parameters.Add("@msg", OleDb.OleDbType.VarChar)
            cmd.Parameters("@msg").Value = "test"

            '*** Try 2, failed
            'Dim param As New OleDb.OleDbParameter
            'param.Value = Msg
            'cmd.Parameters.AddWithValue("@msg", param)

            '*** Try 3, failed
            'cmd.Parameters.Add("@Msg", OleDb.OleDbType.VarChar)
            'cmd.Parameters("@Msg", msg)

            '*** Try 4, failed
            'cmd.Parameters.AddWithValue("@msg", msg)

            cmd.ExecuteNonQuery()

Open in new window

0
Comment
Question by:sidwelle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 39875833
OleDb does not use named parameters. It uses question marks for place holders. Try this:

cmd.CommandText = "UPDATE tblMsgs01 " & _
                  "SET msg = ? " & _
                  "WHERE id = '" & sID & "'"
                  
cmd.Parameters.AddWithValue("@msg", "test")  ' @msg doesn't matter. it can be whatever you like

Open in new window


When you have multiple parameters, you still use the question marks, but you add your parameters to the Parameters collection in the order in which the parameters appear in the query.
0
 

Author Closing Comment

by:sidwelle
ID: 39875874
And it did, Thanks for the help.

Is there a connection that would be better suited to what I am doing than OleDb ?
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39875938
What kind of database are you connecting to?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:sidwelle
ID: 39876669
MS SQL 2005 Enterprize.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39877069
The classes found under the System.Data.SqlClient namespace are typically used to connect to MS SQL. The SqlCommand class does allow named parameters.
0
 

Author Comment

by:sidwelle
ID: 39877637
I switch the project over to using SqlCommand class. had to remove "Provider=SQLOLEDB" from the conn string.
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question