473,320 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Retrieve data columnn info using ADO.NET


I have a function with a dynamic sql block like this (fieldname and
fieldvalue are input parametrs to the function) :

strSQL = "UPDATE myTable SET " + fieldname + "=" + fieldvalue +
"' where myID = " + knr

I have to determine whether fieldname is a string or numeric to get the
correct
SQL syntax.

What is the fastest way to do this? (Code example is very helpful.)

I use SQL server 2000 and vb.net

Jan Erik Hansen
Oslo,Norway
Sep 11 '07 #1
2 1146
use parameters... OK, you can /possibly/ get away with using direct
concatenation for the field-name (assuming that there is no user input
to this), but for the value, the correct syntax is simply:

"... SET FieldName = @Value"

And add a parameter to the command called @Value, with .Value =
fieldValue;

Most importantly, this protects you from injection. I can't do an
example in VB (am a C# person...).

Marc
Sep 11 '07 #2
I am a C# guy, but here is an example:

Marc's Solution is the way to go, but if you must use the dynamic
query in your example code, you can overload your method. Just call
MyMethod and the correct query will get created for you. See Below

function MyMethod(string fieldname, int fieldvalue) {

strSQL = "UPDATE myTable SET " + fieldname + "=" + fieldvalue +
"' where myID = " + knr
}

function MyMethod (string fieldname, string fieldvalue) {

strSQL = "UPDATE myTable SET " + fieldname + "=" + fieldvalue +
"' where myID = " + blah blah
}

Sep 11 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Daniel Tonks | last post by:
First, please excuse the fact that I'm a complete MySQL newbie. My site used forum software that I wrote myself (in Perl) which, up until now, has used flat files. This worked fine, however...
3
by: Javier | last post by:
Hi All I'm retrieving data from a SQL Server with C++. I need to retrieve a row and update some column in this retrieved row. Is this possible ? How could I do it ? Could anybody send me o...
0
by: Dimitris Katsikas | last post by:
Hi everybody, I am trying to find a way to export automatically an entire database schema into an .xsd A graphical way is to drag & drop the tables from Server Connection into an empty .xsd...
1
by: funcSter | last post by:
I want to retrieve data from an Excel file like how I would with a database. I understand that I would have to use OLE DB. Somehow I think I cannot get the connection string right, as the bit of...
5
by: ggk517 | last post by:
We are trying to develop an Engineering application using PHP, Javascript with Informix as the back-end. Is it possible to retrieve data using Javascript but by accessing the Database. Say...
1
by: onceuponapriori | last post by:
Greetings gents. I'm a Railser working on a django app that needs to do some scraping to gather its data. I need to programatically access a site that requires a username and password. Once I...
5
by: Johnny BeGood | last post by:
Hi All, Has anyone got any ideas on how to retrieve mobile phone info from a phone that connects to my web site, I want to use that data as part of logon authentication, for example: <?php...
2
by: jsd219 | last post by:
Hello, i am having problems displaying an image once i have uploaded it. i upload it to a folder and store its name in a database. below is the code to display the image. I have figured out the the...
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.