日期:2014-05-16 浏览次数:20530 次
增加一个图片列:
C#
private void btnQuery_Click(object sender, EventArgs e) { StringBuilder sb=new StringBuilder (); sb.Append(" SELECT 序号, 品号,品名,客户品号,客户编码,客户名称,数量,币种,汇率,原币单价,原币总价,本币单价,本币总价,创建时间"); sb.Append(" FROM UF_Quotation"); sb.Append(" where 1=1 "); if (txtItem.Text.Trim() != "") { sb.Append(" and 品号 like '%" + txtItem.Text.Trim() + "%'"); } if (txtItemName.Text.Trim() != "") { sb.Append(" and 品名 like '%" + txtItemName.Text.Trim() + "%'"); } string dateStart= Convert.ToDateTime(dateTimePicker1.Text.Trim()).ToString("yyyy-MM-dd"); string dateEnd = Convert.ToDateTime(dateTimePicker2.Text.Trim()).ToString("yyyy-MM-dd"); sb.Append(" and convert(char(10),创建时间,120)>='"+dateStart+"'"); sb.Append(" and convert(char(10),创建时间,120)<='" + dateEnd + "'"); DataTable dt = new DataTable(); dt= JB_QuotationDAL.QuotationList(sb.ToString()); dt.Columns.Add("img", typeof(Image)); foreach (DataRow row in dt.Rows) { if (File.Exists(@"D:\产品图片\" + row["品号"].ToString().Trim() + ".jpg")) { //需要判断是否存在图片 Image img = Image.FromFile(@"D:\产品图片\" + row["品号"].ToString().Trim() + ".jpg");//双引号里是图片的路径 row["img"] = img; } else { //需要判断是否存在图片 Image img = Image.FromFile(@"D:\产品图片\LOGO.jpg");//双引号里是图片的路径 row["img"] = img; } } dgvQuotation.DataSource = dt; }