1.  SqlConnection conn = new SqlConnection(@"data source=20110105-1517;initial catalog=消防预警系统;User ID=sa;password=28"); 
  2.  
  3. 数据的更新替换 update Table_1 set 姓名='张晓玲' where 姓名='牛羊' 
  4. 多行替换update Table_1  set 姓名='牛永杰' ,年龄='100' where 姓名='牛永斌' and 工资=100000 
  5. 排序  select 年龄 from Table_1 order by  年龄 desc 
  6. Begin end 结合使用 
  7.  
  8. 很多的SQL语句中要使用end结束(when @str=90 then '你的成绩是优秀' 
  9. end 
  10. print  @str1) 
  11. using System; 
  12. using System.Data; 
  13. using System.Data.SqlClient; 
  14. namespace ConsoleApplication3 
  15.     class Program 
  16.     { 
  17.         static void Main(string[] args) 
  18.         { 
  19.             SqlConnection conn = new SqlConnection(@"server=.;integrated security=true;database=db_business"); 
  20.             //SqlConnection conn = new SqlConnection(@"server=.\db_business;integrated security=true;"); 
  21.             string sql = @"select count (*) from  职工 "
  22.             SqlCommand cmd = new SqlCommand(sql,conn); 
  23.           
  24.             try 
  25.             { 
  26.                 conn.Open(); 
  27.                 Console.WriteLine("打开成功"); 
  28.  
  29.                 Console.WriteLine("结果:{0}",cmd.ExecuteScalar()); 
  30.             } 
  31.             catch (SqlException e) 
  32.             { 
  33.                 Console.WriteLine("错误是:" + e); 
  34.             } 
  35.             finally 
  36.             { 
  37.                 conn.Close(); 
  38.                 Console.WriteLine("连接关闭!"); 
  39.             } 
  40.             Console.Read(); 
  41.  
  42.         } 
  43.     } 
  44.  
  45.             int[] arr = { 1, 2, 3,58,110 };  
  46.             foreach (int i in arr)  
  47.             {  
  48.                 System.Console.WriteLine(i); 
  49.             } 
  50.  
  51. 数据集,数据适配器都是构造函数重载的, 
  52.     string sql = @"select * from  Table_1 "
  53.                 SqlDataAdapter da = new SqlDataAdapter (sql,conn); 
  54.                 DataSet ds = new DataSet(); 
  55.                 da.Fill(ds,"Table_1"); 
  56.                 DataTable dt = ds.Tables["Table_1"]; 
  57.                 foreach(DataRow row in dt.Rows) 
  58.                 { 
  59.                     foreach(DataColumn col in dt.Columns) 
  60.                         Console.WriteLine(row[col]); 
  61.                         Console.WriteLine("".PadLeft(20,'=')); 
  62.  
  63.                 } 
  64.      
  65. 获取dataGridView1控件中的值 
  66.      for (int i = 0; i < dataGridView1.Columns.Count;i++ ) 
  67.             { 
  68.                 string str = ""
  69.                 if (i == 0) 
  70.                 { 
  71.                     str += dataGridView1.Rows[e.RowIndex].Cells[i].Value.ToString(); 
  72.                     textBox1.Text = str; 
  73.                 } 
  74.                 else 
  75.                 { 
  76.                     str += dataGridView1.Rows[e.RowIndex].Cells[i].Value.ToString(); 
  77.                     textBox2.Text = str; 
  78.                 } 
  79.             } 
  80.  ///使用数据适配器操作数据集,并不是直接对数据库的操作, 
  81. //使用sqldataadapt 实现数据的添加 
  82.             SqlCommandBuilder sb = new SqlCommandBuilder(da); 
  83.             DataRow row = ds.Tables[0].NewRow(); 
  84.             row["ID"] = "D7"
  85.             row["AreaName"] = "测a试º?区?3"
  86.             ds.Tables[0].Rows.Add(row); 
  87.             da.Update(ds); 
  88.             dataGridView1.DataSource = ds.Tables[0]; 
  89.             conn.Close (); 
  90. //使用sqldataadapt 删除数据 
  91.           SqlCommandBuilder sqlcb = new SqlCommandBuilder(da); 
  92.             for (int i = 0; i < ds.Tables[0].Rows.Count; i++) 
  93.             {    
  94.                 if(ds.Tables[0].Rows[i][1].ToString()=="测a试º?区?2"
  95.                 { 
  96.                     ds.Tables[0].Rows[i].Delete(); 
  97.                 } 
  98.             } 
  99.             da.Update(ds); 
  100. //使用sqldataadapt 修改数据 
  101.           SqlCommandBuilder sqlcb = new SqlCommandBuilder(da); 
  102.             for (int i = 0; i < ds.Tables[0].Rows.Count; i++) 
  103.             { 
  104.                 if(ds.Tables[0].Rows[i][1].ToString()=="测a试º?区?3"
  105.                 { 
  106.                     ds.Tables[0].Rows[i][1]="测a试º?区?1"
  107.                 } 
  108.             } 
  109.             da.Update(ds); 
  110.