473,324 Members | 2,581 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,324 software developers and data experts.

String and int Issue

vb.net 2003 1.1 web application

Hi there.

Atm I am using this SQL string

SQL = "SELECT Addresses." + tab2LookupCol + " FROM Addresses INNER JOIN
Clients ON Addresses.ID=Clients.AddID WHERE (((Clients." + tab1CheckCol
+ ")='" + checkval + "'))"

However, it will not work where '"checkval"' is a number? I require
int's and strings to be entered in to this variable? Is there a simple
way to get around this?

This data is comming from a databse, so I was thinking maybe I could
use an if statment to check the type of the column and then change the
SQL string based on that, unless anyone can think of a differnt
solution, does anyone know the syntax to check the type of a column?

thanx in advance

Jun 30 '06 #1
4 1118
Bonzol,

Than use the Visual Basic concatenate char & instead of the VisualBasic Add
char +.
(The + will to concatenate to but can give problems)

(In the SQL part it has to be +)

I hope this helps,

Cor
"Bonzol" <Bo****@hotmail.com> schreef in bericht
news:11********************@i40g2000cwc.googlegrou ps.com...
vb.net 2003 1.1 web application

Hi there.

Atm I am using this SQL string

SQL = "SELECT Addresses." + tab2LookupCol + " FROM Addresses INNER JOIN
Clients ON Addresses.ID=Clients.AddID WHERE (((Clients." + tab1CheckCol
+ ")='" + checkval + "'))"

However, it will not work where '"checkval"' is a number? I require
int's and strings to be entered in to this variable? Is there a simple
way to get around this?

This data is comming from a databse, so I was thinking maybe I could
use an if statment to check the type of the column and then change the
SQL string based on that, unless anyone can think of a differnt
solution, does anyone know the syntax to check the type of a column?

thanx in advance

Jun 30 '06 #2

well :-|

SQL = "SELECT Addresses." + tab2LookupCol + " FROM Addresses INNER JOIN
Clients ON Addresses.ID=Clients.AddID WHERE (((Clients." + tab1CheckCol +
")='" + checkval + "'))"

if the variabel column tab1CheckCol is pointing to a numeric column in the
sql database then you should write out without the ''

Alphanumeric column

SQL = "SELECT Addresses." + tab2LookupCol + " FROM Addresses INNER JOIN
Clients ON Addresses.ID=Clients.AddID WHERE (((Clients." + alphanumericCol
+ ")='" + checkval + "'))"

numeric column

SQL = "SELECT Addresses." + tab2LookupCol + " FROM Addresses INNER JOIN
Clients ON Addresses.ID=Clients.AddID WHERE (((Clients." + numericCol +
")=" + checkval + "))"
regards

Michel Posseth [MCP]




"Cor Ligthert [MVP]" wrote:
Bonzol,

Than use the Visual Basic concatenate char & instead of the VisualBasic Add
char +.
(The + will to concatenate to but can give problems)

(In the SQL part it has to be +)

I hope this helps,

Cor
"Bonzol" <Bo****@hotmail.com> schreef in bericht
news:11********************@i40g2000cwc.googlegrou ps.com...
vb.net 2003 1.1 web application

Hi there.

Atm I am using this SQL string

SQL = "SELECT Addresses." + tab2LookupCol + " FROM Addresses INNER JOIN
Clients ON Addresses.ID=Clients.AddID WHERE (((Clients." + tab1CheckCol
+ ")='" + checkval + "'))"

However, it will not work where '"checkval"' is a number? I require
int's and strings to be entered in to this variable? Is there a simple
way to get around this?

This data is comming from a databse, so I was thinking maybe I could
use an if statment to check the type of the column and then change the
SQL string based on that, unless anyone can think of a differnt
solution, does anyone know the syntax to check the type of a column?

thanx in advance


Jun 30 '06 #3
Hello, Bonzol,

If I understand correctly, you want to use the same statement to
generate a query applicable to either the case that tab1CheckCol refers
to a text field or a numeric field. So you need to be able to determine
the field type at run time in order to decide whether or not to include
quotation marks around the field.

I am only familiar with Access. There, I believe that you can find the
field type through the TableDefs collection of the database object.
From memory, it was something like:

db.TableDefs(table).Fields(field).DataType

It's probably also possible (but likely different) for other DBs. What
are you using?

Cheers,
Randy
Bonzol wrote:
vb.net 2003 1.1 web application

Hi there.

Atm I am using this SQL string

SQL = "SELECT Addresses." + tab2LookupCol + " FROM Addresses INNER JOIN
Clients ON Addresses.ID=Clients.AddID WHERE (((Clients." + tab1CheckCol
+ ")='" + checkval + "'))"

However, it will not work where '"checkval"' is a number? I require
int's and strings to be entered in to this variable? Is there a simple
way to get around this?

This data is comming from a databse, so I was thinking maybe I could
use an if statment to check the type of the column and then change the
SQL string based on that, unless anyone can think of a differnt
solution, does anyone know the syntax to check the type of a column?

thanx in advance

Jun 30 '06 #4
You might be able to kill 2 birds with one stone by using parameterized queries.
Try the following:

SQL = "SELECT Addresses." + tab2LookupCol + _
" FROM Addresses INNER JOIN " & _
"Clients ON Addresses.ID=Clients.AddID " & _
"WHERE (((Clients." & tab1CheckCol & ")=@ColumnVal & "))"
CMD.CommandText = SQL
CMD.Parameters.Add("@ColumnVal", checkval) 'With VB2005 use AddWithValue

This will take care of the differences between the value types as you don't
have to worry about escaping the string value with the single quote. It will
also take care of the option for SQL injection.
Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
Atm I am using this SQL string

SQL = "SELECT Addresses." + tab2LookupCol + " FROM Addresses INNER
JOIN Clients ON Addresses.ID=Clients.AddID WHERE (((Clients." +
tab1CheckCol + ")='" + checkval + "'))"

However, it will not work where '"checkval"' is a number? I require
int's and strings to be entered in to this variable? Is there a simple
way to get around this?

Jun 30 '06 #5

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

Similar topics

10
by: Angus Leeming | last post by:
Hello, Could someone explain to me why the Standard conveners chose to typedef std::string rather than derive it from std::basic_string<char, ...>? The result of course is that it is...
11
by: JustSomeGuy | last post by:
I have a structure typedef struct { string a; string b; } atype; string ABC = ("123"); string DEF = ("456");
17
by: Chad Myers | last post by:
I've been perf testing an application of mine and I've noticed that there are a lot (and I mean A LOT -- megabytes and megabytes of 'em) System.String instances being created. I've done some...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
8
by: Ottar | last post by:
I have a few numeric fields, and when I update i get the error: "Input string was not in a correct format". Next line:" System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer&...
47
by: sudharsan | last post by:
could any one please give me a code to reverse a string of more than 1MB .??? Thanks in advance
94
by: smnoff | last post by:
I have searched the internet for malloc and dynamic malloc; however, I still don't know or readily see what is general way to allocate memory to char * variable that I want to assign the substring...
1
by: jwf | last post by:
This question continues on from a previous post "DATE to string" but I think it deserves a new thread. In my previous post I was trying to convert a DATE to string in a NON MFC C++ application...
14
by: Shhnwz.a | last post by:
Hi, I am in confusion regarding jargons. When it is technically correct to say.. String or Character Array.in c. just give me your perspectives in this issue. Thanx in Advance.
1
by: kru | last post by:
Hi All, Simple issue I cannot figure out. I have a multiline textbox, I need to convert the string contents of this textbox into a single line string which I currently write to a textfile. ...
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: 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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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.