C# 开发和使用中的23个技巧(1-10)
[作者]:菩提树下的杨过 [来源]:互联网 [收录时间]:2007-9-9 11:08:06
1.怎样定制VC#DataGrid列标题?
  DataGridTableStyle dgts = new DataGridTableStyle();  
  dgts.MappingName = "myTable"; //myTable为要载入数据的DataTable 
  DataGridTextBoxColumn dgcs = new DataGridTextBoxColumn();  
  dgcs.MappingName = "title_id";  
  dgcs.HeaderText = "标题ID";  
  dgts.GridColumnStyles.Add(dgcs);  
  。。。 
  dataGrid1.TableStyles.Add(dgts);    
   2.检索某个字段为空的所有记录的条件语句怎么写? 
  ...where col_name is null  
  3.如何在c# Winform应用中接收回车键输入? 

  设一下form的AcceptButton. 

  4.比如Oracle中的NUMBER(15),在Sql Server中应是什么? 

  NUMBER(15):用numeric,精度15试试。 

  5.sql server的应用like语句的存储过程怎样写? 

  select * from mytable where haoma like ‘%’ + @hao + ‘%’ 

  6.vc# winform中如何让textBox接受回车键消息(假没没有按钮的情况下)?

  private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) 

  { 

  if(e.KeyChar != (char)13) 

  return;  

  else 

  //do something;  

  }  


  7.为什么(Int32)cmd.ExecuteScalar()赋值给Int32变量时提示转换无效? 

  Int32.Parse(cmd.ExecuteScalar().ToString());   

  8.DataSource为子表的DataGrid里怎样增加一个列以显示母表中的某个字段? 
  在子表里手动添加一个列。

  DataColumn dc = new DataColumn("newCol", Type.GetType("System.String"));  

  dc.Expression = "Parent.parentColumnName";  

  dt.Columns.Add(dc); //dt为子表  


   9.怎样使DataGrid显示DataTable中某列的数据时只显示某一部分? 

  select ..., SUBSTR(string, start_index, end_index) as ***, *** from ***   


  10.如何让winform的combobox只能选不能输入? 

  DropDownStyle 属性确定用户能否在文本部分中输入新值以及列表部分是否总显示。 

  值: 

  DropDown --- 文本部分可编辑。用户必须单击箭头按钮来显示列表部分。 

  DropDownList --- 用户不能直接编辑文本部分。用户必须单击箭头按钮来显示列表部分。 

  Simple --- 文本部分可编辑。列表部分总可见。