Click here to Skip to main content
11,495,656 members (59,845 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL database query
How do you write a C# SELECT Cast Query to combine 3 textbox values and save to the database?

Example:

Given:
height = 5
width = 7
unit = feet

Answer:
Fieldname dimension = 5 x 7 feet

string sql = "SELECT CAST...?"
Posted 2-Jul-12 21:22pm
wolfsor564
Comments
Damith Weerasinghe at 3-Jul-12 3:04am
   
if You need to save the values of text boxes in database, then why you have select sql statement? you need to have insert statement.
Damith Weerasinghe at 3-Jul-12 3:06am
   
Another question, you need to save it as string "5 x 7 feet" or just the value of multiplication like 35?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try
select CAST(height AS varchar) + 'X' + CAST(width AS varchar) + unitl
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

string strDimension = (5*7).ToString()+" feet";
string sql = "Insert Into tableX(dimension) values ('"+strDimension +"')
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Dnyaneshwar@Pune 692
1 CHill60 318
2 Sascha Lefèvre 275
3 Nakul Chaudhari 236
4 Sergey Alexandrovich Kryukov 230
0 Sergey Alexandrovich Kryukov 10,362
1 OriginalGriff 8,821
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600


Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 3 Jul 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100