用户操作
[即时聊天] [发私信] [加为好友]
ahshowID:ahshow
30085次访问,排名4086,好友2人,关注者14人。
.net
ahshow的文章
原创 50 篇
翻译 0 篇
转载 37 篇
评论 9 篇
ahshow的公告
把一点小经验和技巧发在上面,希望自己和看博的人都能得到启发,共同进步!(有什么意见,要求请回复!)

希望看我博客的人多回复,多给点写文章的动力给我。
Google
最近评论
过路的:有用处,多谢了~
houlei:cmd.ExecuteScalar()返回的是首行首列的值,它返回的是Object类型的.不是这个表的行的总数.
19451646:ctl.Value = (DateTime)this.Value;
应该先判断是不是空在转换,否则会出错,大多数情况下初始值都是空的.
ahshow:因为他的sql查询语句是:
select count(*) from Products
这个语句是查询数据总数啊
cmd.ExecuteScalar()返回的是第一行的值
但是返回的是这个表的count就是总数啊

另外提一下,这篇文章是转的,我用代码测试好像没通过,感觉不是很好,你可以看我“原创”的那篇文章“使用ObjectDat……
国语:GetProdcutsCount() 方法中
int count = (int)cmd.ExecuteScalar();

就可以表示查询到的数据总数吗?

cmd.ExecuteScalar()不是只返回第一行的值吗?


文章分类
收藏
    相册
    Blogs
    【孟子E章】
    c#3.0
    flylasly Moto E2 SFC模拟器
    wolf's cave
    代振军BLOG
    叶帆工作室
    宝玉的blog
    开心就好的代码人生
    张合福的专栏
    思归呓语
    愚翁专栏
    房客 的C#集
    星宿.net(WF)
    李洪根
    蝈蝈俊.net
    蝈蝈俊.net(CSDN)
    谭振林(THIN)
    Webs
    codeproject
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 让datagridview或girdview指定的一行或多行变色收藏

    新一篇: c#使用shutdown关机命令让xp和vista关机 | 旧一篇: 非程序的程序员智力面试题

    datagridview的:

    (注意这种方法不是很好,而且网格线都没有了,自找麻烦了,还用了图形的东西,可以看最下面的那种方法。)

    利用datagridview中的RowPrePaint事件。 
    private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e) 

    if (e.RowIndex >= dataGridView1.Rows.Count - 1
    return
    DataGridViewRow dgr 
    = dataGridView1.Rows[e.RowIndex]; 
    try 

    //dgr.Cells[0]是当前性别列的索引值,用以确定判断哪一列的值 
    if (dgr.Cells[0].Value.ToString() == ""

    //定义画笔,使用颜色是深灰。 
    using (SolidBrush brush = new SolidBrush(Color.DarkGray)) 

    //利用画笔填充当前行 
    e.Graphics.FillRectangle(brush, e.RowBounds); 
    //将值重新写回当前行。 
    e.PaintCellsContent(e.ClipBounds); 
    e.Handled 
    = true
    }
     
    }
     
    }
     
    catch (Exception ex) 

    MessageBox.Show(ex.Message); 
    }
     

    }

     gridview的:

    protected void gvwResult_RowDataBound(object sender, GridViewRowEventArgs e) 


    if(((Label)e.Row.FindControl("lblSex")).Text = ""

    ((Label)e.Row.ForeColor 
    = Color.DarkGray; 
    }
     
    }

    上面的datagirdview变色的方法不是好的方法,而且网格线都没了,下面这种方法比较好:

    private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
            
    {
                
    if (e.RowIndex >= dataGridView1.Rows.Count - 1)
                
    return;
                DataGridViewRow dgr 
    = dataGridView1.Rows[e.RowIndex];
                
    try
                
    {
                    
    for (int i = 0; i < dataGridView1.Rows.Count; i++)
                    
    {
                        
    //dgr.Cells[0]是当前性别列的索引值,用以确定判断哪一列的值 
                        if (dgr.Cells[1].Value.ToString() == "使用中")
                        
    {
                            dgr.DefaultCellStyle.BackColor 
    = Color.Red;
                        }

                        
    else
                        
    {
                            dgr.DefaultCellStyle.BackColor 
    = Color.Green;
                        }

                    }

                }

                
    catch (Exception)
                
    {
                }

    }

    发表于 @ 2007年11月29日 09:49:00|评论(loading...)|编辑

    新一篇: c#使用shutdown关机命令让xp和vista关机 | 旧一篇: 非程序的程序员智力面试题

    评论:没有评论。

    发表评论  


    登录
    Csdn Blog version 3.1a
    Copyright © ahshow