0909,03
Decimal(p[,s])
0909,11Decimal(p[,s])
decimal(p[,s]),其中p为精度,s为小数位数
p(精度)最多可以存储的十进制数字的总位数,包括小数点左边和右边的位数
s(小数位数)小数点右边可以存储的十进制数字的最大位数
1.在保证小数位且总位数不超过6时
declare @a decimal(6,3)
set @a=56.342689
print @a
得到
56.343
2.在保证小数位且总位数超过6时
declare @a decimal(6,3)
set @a=1156.345
print @a
报错
p(精度)最多可以存储的十进制数字的总位数,包括小数点左边和右边的位数
s(小数位数)小数点右边可以存储的十进制数字的最大位数
1.在保证小数位且总位数不超过6时
declare @a decimal(6,3)
set @a=56.342689
print @a
得到
56.343
2.在保证小数位且总位数超过6时
declare @a decimal(6,3)
set @a=1156.345
print @a
报错
Error: 线程间操作无效: 从不是创建控件“”的线程访问它。
以下是一个偷懒的解决办法
Control.CheckForIllegalCrossThreadCalls = false;
使用前请注意:该方法只是简单的将错误提示禁用了,仍然存在跨线程调用控件的问题。为此可能造成两个线程同时或者循环改变该控件的状态导致线程死锁。如果要根本性的解除问题,得用Invoke方法,因为Invoke是同步的方法,所以执行过程是有先后顺序的。0909,18
datagridview改变某行的字体
//字体加粗,字体样式等的改变
dataGridView1.Rows[1].DefaultCellStyle.Font = new Font("宋体",12,FontStyle.Bold,GraphicsUnit.Pixel);
dataGridView1.Rows[1].DefaultCellStyle.Font = new Font("宋体",12,FontStyle.Bold,GraphicsUnit.Pixel);
0910,20
IList <>与List <>区别
IList <>是个接口,定义了一些操作方法 这些方法要你自己去实现
List <>是个类型 已经实现了IList <>定义的那些方法
一般情况下,建议使用IList<>,效率更高,可扩展性更高。
0910,28
DataTable取前N条记录
DataTable table = ds.Tables[0];
DataColumn column = new DataColumn( "id ", typeof(int));
column.AutoIncrement = true;
column.AutoIncrementSeed = 1;
column.AutoIncrementStep = 1;
table.Columns.Add(column);
table.Select( "id <=10 ");
0910,29DataColumn column = new DataColumn( "id ", typeof(int));
column.AutoIncrement = true;
column.AutoIncrementSeed = 1;
column.AutoIncrementStep = 1;
table.Columns.Add(column);
table.Select( "id <=10 ");
String.Concat(string[])连接指定的String数组
0911,06
DataGridView显示行号 只需编辑一个事件“_RowPostPaint”
private void gridMain_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
//显示行号
Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
e.RowBounds.Location.Y,
this.gridMain.RowHeadersWidth - 4,
e.RowBounds.Height);
TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
this.gridMain.RowHeadersDefaultCellStyle.Font,
rectangle,
this.gridMain.RowHeadersDefaultCellStyle.ForeColor,
TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
}
{
//显示行号
Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
e.RowBounds.Location.Y,
this.gridMain.RowHeadersWidth - 4,
e.RowBounds.Height);
TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
this.gridMain.RowHeadersDefaultCellStyle.Font,
rectangle,
this.gridMain.RowHeadersDefaultCellStyle.ForeColor,
TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
}
DataGridView隐藏CurrentRowHead中的三角箭头
Grid.RowHeadersDefaultCellStyle.Padding = New Padding(Grid.RowHeadersWidth)
SQL SERVER 新增一行可以如此照搬!!(Insert ... Select ...)
--新增一行可以如此照搬!!
INSERT INTO BAS_ColorGroup_TBL
SELECT 14,SizeGroupName FROM BAS_SizeGroup_TBL WHERE SizeGroupID=2
INSERT INTO BAS_ColorGroup_TBL
SELECT 14,SizeGroupName FROM BAS_SizeGroup_TBL WHERE SizeGroupID=2
SQL SERVER (group by)分组 (原来可以这样,你可把我搞死喽。。。)
SUM(case C when 'Y' then 1 else -1 end) as **
2009.11,20
//
DataGridView当前行相对应的DataRow
DataRow dataRow = (dataGridViewRow.DataBounditem as DataRowView).Row;
Combobox当前行相对应的DataRow
//DataRowView item = (DataRowView)Combobox1.Items[0];
DataRow dr = (Combobox1.Items[0] as DataRowView).Row;
DataRow dr = (Combobox1.Items[0] as DataRowView).Row;
//
SQL知识:6除以7 如果你想得到小数,就得这么写
Convert(decimal(6,2),Convert(decimal,6)/7),
//给ComboBox添加空行
DataSet ds = ;
DataTable dt = ds.Tables[0];
// 空行
DataRow dr = dt.NewRow();
dt.Rows.InsertAt(dr, 0);
//
comboBox1.DataSource=dt.DefaultView;
comboBox1.DisplayMember = "VisitanLevelName";
comboBox1.ValueMember = "VisitanLevelID";
DataTable dt = ds.Tables[0];
// 空行
DataRow dr = dt.NewRow();
dt.Rows.InsertAt(dr, 0);
//
comboBox1.DataSource=dt.DefaultView;
comboBox1.DisplayMember = "VisitanLevelName";
comboBox1.ValueMember = "VisitanLevelID";
// 懒得写...
代码
///<LinkLabel 控件还可用于使用默认浏览器显示网页:>
/// <summary>
/// 图片链接
/// </summary>
private void linkPICUrl_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
try
{
linkPICUrl.LinkVisited = true;
System.Diagnostics.Process.Start(txtPICUrl.Text.Trim());
}
catch
{
Tool.ShowMessage("打开图片失败!",MessageBoxIcon.Error);
}
}
}
///<DataGridView 控件中添加包含链接的单元格的列:>
private void AddLinkColumn()
{
DataGridViewLinkColumn links = new DataGridViewLinkColumn();
links.HeaderText = ColumnName.ReportsTo.ToString();
links.DataPropertyName = ColumnName.ReportsTo.ToString();
links.ActiveLinkColor = Color.White;
links.LinkBehavior = LinkBehavior.SystemDefault;
links.LinkColor = Color.Blue;
links.TrackVisitedState = true;
links.VisitedLinkColor = Color.YellowGreen;
DataGridView1.Columns.Add(links);
}
/// <summary>
/// 图片链接
/// </summary>
private void linkPICUrl_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
try
{
linkPICUrl.LinkVisited = true;
System.Diagnostics.Process.Start(txtPICUrl.Text.Trim());
}
catch
{
Tool.ShowMessage("打开图片失败!",MessageBoxIcon.Error);
}
}
}
///<DataGridView 控件中添加包含链接的单元格的列:>
private void AddLinkColumn()
{
DataGridViewLinkColumn links = new DataGridViewLinkColumn();
links.HeaderText = ColumnName.ReportsTo.ToString();
links.DataPropertyName = ColumnName.ReportsTo.ToString();
links.ActiveLinkColor = Color.White;
links.LinkBehavior = LinkBehavior.SystemDefault;
links.LinkColor = Color.Blue;
links.TrackVisitedState = true;
links.VisitedLinkColor = Color.YellowGreen;
DataGridView1.Columns.Add(links);
}
//2010.01.19
设置Winform窗体快捷键事件
窗体快捷键
/// <summary>
/// 设置下级的事件
/// </summary>
/// <param name="superControl"></param>
private void SetLowerEvent(Control superControl)
{
foreach (Control control in superControl.Controls)
{
if (control is DISTR.Controls.Filter.FilterControl) continue;
control.KeyDown += new KeyEventHandler(AllControl_KeyDown);
SetLowerEvent(control);
}
}
/// <summary>
/// 所有控件的KeyDown事件处理
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AllControl_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
ReturnCancel();
}
else if (e.KeyCode==Keys.Enter)
{
e.Handled = true;
this.ReturnOK();
}
}
// winform Load事件中调用
SetLowerEvent(this);
/// 设置下级的事件
/// </summary>
/// <param name="superControl"></param>
private void SetLowerEvent(Control superControl)
{
foreach (Control control in superControl.Controls)
{
if (control is DISTR.Controls.Filter.FilterControl) continue;
control.KeyDown += new KeyEventHandler(AllControl_KeyDown);
SetLowerEvent(control);
}
}
/// <summary>
/// 所有控件的KeyDown事件处理
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AllControl_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
ReturnCancel();
}
else if (e.KeyCode==Keys.Enter)
{
e.Handled = true;
this.ReturnOK();
}
}
// winform Load事件中调用
SetLowerEvent(this);
//2010.05.05
有关DataTable之Distinct
DataView dataView = dataTable.DefaultView;
dataView.ToTable(true,"FieldName1","FieldName2","...");
//注:其中ToTable()的第一个参数为是否DISTINCT
dataView.ToTable(true,"FieldName1","FieldName2","...");
//注:其中ToTable()的第一个参数为是否DISTINCT
隐藏numericUpDown控件之上移下移
//VB
Dim RGN As Region = New Region(New Rectangle(0, 0, 左侧文本框宽度, 左侧文本框高度))
NumericUpDown1.Region = RGN
Dim RGN As Region = New Region(New Rectangle(0, 0, 左侧文本框宽度, 左侧文本框高度))
NumericUpDown1.Region = RGN
普通字符串转化为16进制字符串
string ret = System.BitConverter.ToString(System.Text.UnicodeEncoding.GetEncoding("GB2312").GetBytes("中国China"));