12,300,021 members (53,553 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Please correct the code:

```cmdupdate.CommandText = "Insert Into RawMat " +
" (ProductDimension) " +
" VALUES ('" + txtwidth.Text + "', '" + txtheight.Text + "', '" + txtunitofmeasurement.Text + "')";
cmdupdate.ExecuteNonQuery();
```

Output:

Given:
height = 5
width = 7
unit = feet

Answer:
dimension = 5 x 7 feet
Posted 2-Jul-12 21:12pm
wolfsor564

## 2 solutions

Rate this:
Please Sign up or sign in to vote.

## Solution 1

```cmdupdate.CommandText = "Insert Into RawMat " +
" (ProductDimension) " +
" VALUES ('" + txtwidth.Text + " X " + txtheight.Text + " " + txtunitofmeasurement.Text + "')";
cmdupdate.ExecuteNonQuery();```
Rate this:
Please Sign up or sign in to vote.

## Solution 2

1) you can concatenate in tsql with + sing

2) why don't you concatenate in C#?
3) use parameters for statement building (avoid exposing your app to SQLinjection)

```cmdupdate.CommandText = "Insert Into RawMat (ProductDimension) VALUES (@dim)";
cmdupdate.Parameters.AddWithValue("@dim", string.Format("{0} x {1} {2}", txtwidth.Text, txtheight.Text, txtunitofmeasurement.Text));```
v2
Comments
wolfsor 3-Jul-12 3:48am

how do you add WHERE ProductNo=@Pno
Zoltán Zörgő 3-Jul-12 4:05am

WHERE clause in this insert statement? I don't understand. In a select you can do it just like here. If data type of the parameter is not detectable, you can use Add method and then set the value. Consult MSDN.
Zoltán Zörgő 4-Jul-12 17:14pm

any progress?

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

Top Experts
Last 24hrsThis month
 Karthik Bangalore 250 Richard MacCutchan 225 Garth J Lancaster 220 OriginalGriff 172 ppolymorphe 165
 OriginalGriff 9,787 ppolymorphe 5,901 CHill60 5,497 Karthik Bangalore 5,276 Richard MacCutchan 5,099

Advertise | Privacy | Mobile
Web02 | 2.8.160525.2 | Last Updated 3 Jul 2012
Copyright © CodeProject, 1999-2016
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