.Net对数据库的绑定

 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OracleClient;
using System.Data.OleDb; namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void BuildColor()
{
for (int i = ; i < this.dataGridView1.Rows.Count; i++)
{
if (this.dataGridView1[, i] != null && this.dataGridView1[, i].Value != null)
{
// 根据条件设置不同的颜色
if (this.dataGridView1[, i].Value.ToString() == "")
this.dataGridView1[, i].Style.BackColor = Color.Blue;
else if (this.dataGridView1[, i].Value.ToString() == "")
this.dataGridView1[, i].Style.BackColor = Color.Yellow;
}
}
} private void btnGetData_Click(object sender, EventArgs e)
{
using (OracleConnection conn =
new OracleConnection("data source=10.21.144.152/JXWSQZJ;User Id=qzj_bak;Password=qzj_bak;"))
{
OracleCommand cmd = conn.CreateCommand();
cmd.CommandText = "select * from TB_YL_MZ_MEDICAL_RECORD where rownum<100";
conn.Open(); OracleDataReader odr = cmd.ExecuteReader();
OracleDataAdapter sda = new OracleDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds, "TB_YL_MZ_MEDICAL_RECORD");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "TB_YL_MZ_MEDICAL_RECORD"; //上面两句等价于 dataGridView1.DataSource = ds.Tables["TB_YL_MZ_MEDICAL_RECORD"]
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
dataGridView1.Columns[].HeaderText = "测试";
foreach (DataGridViewColumn col in dataGridView1.Columns)
{
if (col.Name == "KH")
{ col.HeaderText = "aaaa"; }
}
this.BuildColor();
}
} private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“yygl_jxDataSet.CLGL_Import”中。您可以根据需要移动或删除它。
//dataGridView1.Dock = DockStyle.Fill;
//dataGridView1.DataSource = System.Drawing.Imaging.ImageCodecInfo.GetImageDecoders();
} private void cLGLImportBindingSource_CurrentChanged(object sender, EventArgs e)
{ } private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(e.RowBounds.Location.X,
e.RowBounds.Location.Y,
dataGridView1.RowHeadersWidth - ,
e.RowBounds.Height); TextRenderer.DrawText(e.Graphics, (e.RowIndex + ).ToString(),
dataGridView1.RowHeadersDefaultCellStyle.Font,
rectangle,
dataGridView1.RowHeadersDefaultCellStyle.ForeColor,
TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
} private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
for (int i = ; i < this.dataGridView1.Rows.Count; i++)
{
if (i % == )
{
this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.LightGreen;
//this.dataGridView1.Rows[i].DefaultCellStyle.Font = Font.;
}
else
{
this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.LightBlue;
//this.dataGridView1.Rows[i].DefaultCellStyle.Font = this.splitContainer1.Font;
}
}
}
}
}

C#数据库绑定的更多相关文章

  1. cxGrid 增加序号 (非数据库绑定模式) (测试通过)

    cxGrid 增加序号 (非数据库绑定模式) ----------------------------------- 1. 选在 adoQuery 控件 , 鼠标右键菜单中 选择 Fields Edi ...

  2. DB2 数据库绑定用户授权命令

    1.1  数据库绑定用户授权命令 db2 connect to opca db2 grant dbadm,createtab,bindadd,connect,create_not_fenced_rou ...

  3. 共享参数ContentProvider 类与数据库绑定,如何通过共享参数测试类,测试数据库的增删改查功能

    Intent可以传一个对象 当两个界面之间跳转时,需要传递一个对象过去,是通过使用Bundle类,并且实体类需要serializable实现序列化,传递方法如下: 定义一个静态常量作为key值 pub ...

  4. GridView的HyperLinkField的DataNavigateUrlFormatString如何使用自定义的变量,而不是数据库绑定的值

    GridView的HyperLinkField的DataNavigateUrlFormatString如何使用自定义的变量,而不是数据库绑定的值.报错:指定的参数已超出有效值的范围.参数名: inde ...

  5. 母版页 treeview控件 SiteMapPath控件 treeview数据库绑定模式

     母版页就是网站中一样的部分母版页的后缀名是.Master可以把母版页当成一个页面  想让哪里是别的内容就可以  通过如下: <asp:ContentPlaceHolder ID="C ...

  6. C#中TreeView与数据库绑定

    protected void CreateTreeView() { TreeNode rootNode = new TreeNode(); rootNode.Text = "全部" ...

  7. 使用数据库绑定ListBox控件

    1. The HTML Markup <div> <asp:ListBox ID="ListBox1" runat="server">& ...

  8. ASP.NET 读数据库绑定到 TreeView 递归方式

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs& ...

  9. ASP.NET Gridview数据库绑定支持增删改,记得要完整实现

    1.错误情况 /WebSite3"应用程序中的服务器错误. 指定的参数已超出有效值的范围. 参数名: index 说明: 执行当前 Web 请求期间,出现未经处理的异常.请检查堆栈跟踪信息, ...

随机推荐

  1. nop 添加字段

    一.Libraries 1.core 层------------实体字段 2.data-Map----------映射到数据库 二.Admin 1.Models  --------admin界面模型  ...

  2. Bing Map

    To use map services in Windows 10 packages for this application, you need to acquire a token from th ...

  3. [更新中]并发和并行(Concurrency and Parallelism)

    书籍的简称: CSPPSE: Computer System: a programmer's perspective Second Edition 术语并发是一个通用的概念, 指同时具有多个活动的系统 ...

  4. 四色定理+dfs(poj 1129)

    题目:Channel Allocation 题意:要求A:BCD,A与B,C,D都不相同,求不同的值,典型的四色定理: #include <iostream> #include <a ...

  5. 不用ide编译java程序时调用jar包

    调用特定目录下的jar包 javac -cp d:\javatest\dom4j.jar Dom4jDemo.java //这部分必须注意,d:\javatest 是Dom4jDemo.class所在 ...

  6. 一个创建Coco2d-x项目的脚本

    1.使用环境 我测试的环境是Mac OS 10.10 +Coco2d-x 3.2,是使用shell写的脚本,应该linux/unix都应该 可以使用. 2.使用可能出现的问题 使用中可能会爆权限不足的 ...

  7. linux-5重要进程守护

    当给一台主机安装上linux系统后可以工作了-包括接受用户的输入/计算/存储/再将结果输出等等,这都是系统服务帮助我们完成的.而有一些系统服务时刻等待用户的输入(r如键盘进程)或随时响应用户的请求(如 ...

  8. EmberJs之使用Ember-Data

    写在前面 最近比较忙,换了新工作还要学习很多全新的技术栈,并给自己找了很多借口来不去坚持写博客.常常具有讽刺意味的是,更多剩下的时间并没有利用而更多的是白白浪费,也许这就是青春吧,挥霍吧,这不是我想要 ...

  9. 手机H5 web调试利器——WEINRE (WEb INspector REmote)

    手机H5 web调试利器--WEINRE (WEb INspector REmote) 调试移动端页面,优先选择使用chrome浏览器调试,如果是hybrid形式的页面,可以使用chrome提供的ch ...

  10. [游戏学习28] MFC 时钟

    >_<:这是一个时钟小程序 >_<:通过调用获得系统时间然后经过计算得出当前时间,然后再以3个圆环表示时分秒. >_<:TAO_CLOCK.h class CMyA ...