[ DB ][ SQL Server ] [C#] C# using DML to insert and update DML

C#  using DML to insert and update DML,

using Northwind database as example

======================================================================================== 

insert

DateTime date1 = dateTimePicker1.Value.Date;
string dateStr1 = date1.ToString("yyyy-MM-dd hh:mm:ss", System.Globalization.CultureInfo.InvariantCulture);

String insertSQL =

"Insert into orders "+

" (OrderID, CustomerID, EmployeeID, OrderDate, RequiredDate, ShippedDate, ShipVia, Freight, ShipName, ShipAddress, ShipCity, ShipRegion, ShipPostalCode,  ShipCountry) " +
" values(" + textBox1.Text + ", '" + comboBox1.Text + "', " + comboBox2.Text + ", '" + dateStr1 + "', '" + dateStr2 + "', '" + dateStr3 + "', " +
comboBox3.Text + ", '" + textBox2.Text + "', '"+ textBox3.Text + "', '" + textBox4.Text + "', '"+textBox5.Text+ "', '"+
textBox6.Text + "', '" + textBox7.Text + "', '" + textBox8.Text + "' ) ";

 

======================================================================================== 

update

 string updatesql = 
  " update orders set " +
 " CustomerID ='"+comboBox1.Text+"', EmployeeID ="+comboBox2.Text+
  ", OrderDate='" + dateTimePicker1.Value.ToString("yyyy-MM-dd hh:mm:ss") + "' " +", RequiredDate = '" +dateTimePicker2.Value.ToString("yyyy-MM-dd hh:mm:ss") + "', ShippedDate ='"+dateTimePicker3.Value.ToString("yyyy-MM-dd hh:mm:ss") +"' "+ 
  
  ", ShipVia ="+ comboBox3.Text+", Freight ='"+ textBox2.Text+"', ShipName ='"+ textBox3.Text+"' "+
  
 ", ShipAddress ='"+ textBox4.Text+"', ShipCity ='"+ textBox5.Text+"', ShipRegion ='"+ textBox6.Text+"' "+
 ", ShipPostalCode ='"+ textBox7.Text+"', ShipCountry = '"+textBox8.Text+"' "+
 " where OrderID=" + textBox1.Text;

 

======================================================================================== 

 

 

posted @ 2012-12-05 14:09  Vincent Lee  阅读(210)  评论(0编辑  收藏  举报