.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. freeCodeCamp:Title Case a Sentence

    确保字符串的每个单词首字母都大写,其余部分小写. 像'the'和'of'这样的连接符同理. /*思路 将字符串转为小写.toLowerCase() 分割字符串以单词形式组成数组myarr 确保数组中的 ...

  2. LeetCode(76) Minimum Window Substring

    题目 Given a string S and a string T, find the minimum window in S which will contain all the characte ...

  3. public <T> void show(T t),void前面的泛型T是什么作用

    public <T>这个T是个修饰符的功能,表示是个泛型方法,就像有static修饰的方法是个静态方法一样. <T> 不是返回值,表示传入参数有泛型 public static ...

  4. Mysql --分区表(1)

    检查是否支持分区 通过如下命令检查的Mysql是否支持partition mysql> SHOW PLUGINS; ... | ARCHIVE | ACTIVE | STORAGE ENGINE ...

  5. 跟服务器交互的Web表单(form)

    使用HTML来构建可以跟服务器交互的Web表单(form),通过给你的form元素添加一个action属性来达到此目的. action属性的值指定了表单提交到服务器的地址. 例如: <form ...

  6. alt属性

    也被称为alt text, 是当图片无法加载时显示的替代文本.alt属性对于盲人或视觉损伤的用户理解一幅图片中所描绘的内容非常重要,搜索引擎也会搜索alt属性. 简而言之,每一张图片都应该有一个alt ...

  7. 从Mono 4.0观C# 6.0部分新特性

    Struct的默认构造函数 struct Complex { public Int32 Re { get; set; } public Int32 Im { get; set; } public Co ...

  8. Redis使用总结之与Memcached异同

    Redis是什么?两句话可以做下概括: 1. 是一个完全开源免费的key-value内存数据库 2. 通常被认为是一个数据结构服务器,主要是因为其有着丰富的数据结构 strings.map. list ...

  9. libevent (二) 接收TCP连接

    libevent 接收TCP连接 Evconnlistener 机制为您提供了侦听和接受传入的 TCP 连接的方法.下面的函数全部包含在`<event2/listener.h>`中. ev ...

  10. 解析json实例

    解析项目目录中的一个json文件,将之转化为List的一个方法. package com.miracles.p3.os.util; import com.miracles.p3.os.mode.Vid ...