Click here to Skip to main content
12,300,021 members (53,553 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# SQL database
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
Rate this: bad
 
good
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();
  Permalink  
Rate this: bad
 
good
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));
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


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