惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
B
Blog
Last Week in AI
Last Week in AI
Jina AI
Jina AI
WordPress大学
WordPress大学
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
宝玉的分享
宝玉的分享
T
Tailwind CSS Blog
P
Proofpoint News Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
Google DeepMind News
Google DeepMind News
U
Unit 42
雷峰网
雷峰网
J
Java Code Geeks
Apple Machine Learning Research
Apple Machine Learning Research
MongoDB | Blog
MongoDB | Blog
F
Fortinet All Blogs
美团技术团队
Y
Y Combinator Blog
腾讯CDC
B
Blog RSS Feed
T
The Blog of Author Tim Ferriss
Microsoft Azure Blog
Microsoft Azure Blog
Recent Announcements
Recent Announcements

博客园 - 喝咖啡就蒜瓣儿

通过六段代码理解join、wait、sleep、yield、endInvoke、Waitone的区别 JWT(JSON Web Tokens )简洁说明 通道、选区和蒙版:写给Ps初学者的参考 数据库中Schema(模式)概念的理解 怎样测试串口和串口线是否正常 DataTable如何删除特定行 Difference between WCF and Web API and WCF REST and Web Service C#创建带参数的线程 Application.DoEvents()和多线程 .NET Framework 工具 【转】实现Sqlite datediff日期时间相减的方法 Devexpress GridView增加CheckBox列 没有注册类 (异常来自 HRESULT:0x80040154 (REGDB_E_CLASSNOTREG)) 如何让Advanced Installer卸载软件时保留一些文件 【转】SQLite提示database disk image is malformed的解决方法 【转】Winform下KeyDown,KeyPress,KeyUp事件的总结 【转】C# 子窗体如何调用父窗体的方法 C# WinForm自定义控件响应键盘事件 DataTable中如何去除重复的项【转】 Sqlite: unable to open database file
TAG的用法和用途[转]
喝咖啡就蒜瓣儿 · 2014-09-19 · via 博客园 - 喝咖啡就蒜瓣儿

用一个例子来说明:一个combobox控件...一个textBox控件...一个datagridview控件!
datagridview控件是连接数据库的...
combobox和textBox是联合查询的!!!!
要求:根据combobox的下拉选项(有N个)和textBox的值结合查询...
比如:"select * from tablename where " + combobox.Tag.ToString() + " = " + textBox.Text.ToString() ;
为什么要用Tag呢?
在combobox的下拉选项里,一般都是文字说明:比如:按编号查询,,按名字查询等等..
但是..我们的数据库设计的时候,,字段可能是ID..Name等等...
这时..我们可以在combobox的SelectedIndexChanged事件(就是选择下拉选项发生变化时)
给combobox的Tag赋一个值,这个值就是和数据库字段对应的值...
比如:
if(combobox.SelectedIndex == 0)
{
   combobox.Tag = "ID";
}
if(combobox.SelectedIndex == 1)
{
  combobox.Tag = "name";
}
...
...
这就保证了查询时的一致和正确!
因为..Tag是不可见的(运行时)..所以..是一个很好的做标记用的...!

posted on 2014-09-19 09:47  喝咖啡就蒜瓣儿  阅读(1249)  评论()    收藏  举报