Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Oledb   command text

Posted on 2013-06-07
9
Medium Priority
?
347 Views
Last Modified: 2013-06-08
Visual Studio 2010  Vb.net

I want to write these values to the database

using this  but I am not sure of the sintax

cn = New OleDb.OleDbConnection
        cn.ConnectionString = (My.Settings.cnStringAdo1)
        command = New OleDb.OleDbCommand
        command.Connection = cn
        command.Connection.Open()
        command.CommandText = ("UPDATE [3320Monitor].MASTERSCHEDULE (BOXES,CUT,CODE) where CODE='" & txtcode.Text + "'")
        command.ExecuteNonQuery()
        command.Connection.Close()

I want to overwrite the records  based on teh TXTCODE.TEXT

The fields I want to update BOXES, CUT, CODE   their values come from a TXTBOXES.TEXT and TXTCUT.TEXT and TXTCODE.TeXT


AGAIN is WINDOWS FORMS 2010 VB
0
Comment
Question by:teogos
[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
  • 4
  • 3
  • 2
9 Comments
 
LVL 25

Accepted Solution

by:
Ron Malmstead earned 2000 total points
ID: 39229609
command.CommandText = "UPDATE [3320Monitor].MASTERSCHEDULE SET BOXES='" & TXTBOXES.TEXT & "',CUT='" & TXTCUT.TEXT & " where CODE='" & txtcode.Text & "'"

..also, if you do

Dim RecordsCount as integer = command.ExecuteNonQuery()

You'll get the number of records affected.
0
 

Author Comment

by:teogos
ID: 39229643
command.ExecuteNonQuery()  error here unclosed quotation mark after the character string
0
 
LVL 25

Expert Comment

by:Ron Malmstead
ID: 39229731
Sorry... I forgot a single quote
TXTCUT.TEXT & "' where
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 

Author Comment

by:teogos
ID: 39229835
Error converting data type varchar to numeric    BOXES AND CUT ARE numeric on the database I can't change that
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39229879
You would be better served if you used parameterized queries.

e.g.

command.CommandText = ("UPDATE [3320Monitor].MASTERSCHEDULE SET BOXES = ?, CUT = ? where CODE= ?")
command.Parameters.AddWithValue("?", Convert.ToInt32(TXTBOXES.TEXT))
command.Parameters.AddWithValue("?", Convert.ToInt32(TXTCUT.TEXT))
command.Parameters.AddWithValue("?", Convert.ToInt32(TXTCODE.TeXT))

Open in new window


There's no error handling in the above, so if either text box does not contain a valid integer, then you will encounter an exception. You would want to account for this, of course. Also, it's not clear from my example above, but the order that you add the parameters to the command object must be the same as how they appear in the query (for future reference).
0
 
LVL 25

Expert Comment

by:Ron Malmstead
ID: 39229883
Then you must have non-numeric characters in the textboxes?

You'll need to check for that in code.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39229885
@xuserx2000

No, you need to remove the single quotes you added in the query from around the numeric values  ; )
0
 
LVL 25

Expert Comment

by:Ron Malmstead
ID: 39230077
ahhh... you're right sir.  But I agree with using the parameratized method though, which you posted.
0
 

Author Comment

by:teogos
ID: 39231855
I got to it work using this
command.CommandText = "UPDATE [3320Monitor].MASTERSCHEDULE SET BOXES='" & Val(txtboxes.Text) & "',CUT='" & Val(txtcut.Text) & "' where CODE='" & txtcode.Text & "'"
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

636 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