C# 窗体程序对数据库的操作(SQL或ACCESS),了解不够,有好多问题,求指教。。 因为刚接触不久,目前只知道用DataGridView来显示表数据,但是对数据库的操作肯定不止这些,我想知道的是,怎么用控件或其他方法显示数据库中的图片(储存的是路径)或者指定某个字段的内容显示到窗体上,这功能我做asp.net时用Linq很简单就搞定了,但是刚做窗体程序,就不知道怎么做,不知到说不说得清楚,求指教!!SQLC#数据库 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 有没有方法像做网站一样用差不多跟Repeater控件功能一样或差不多的方法来显示数据库内容。 private void 显示图像(string 文件全路径名称) { PictureBox 图像显示 = new PictureBox(); this.BeginInvoke(new Action(() => { if (文件全路径名称 != null) { Bitmap 原始图像 = new Bitmap(文件全路径名称);//得到原始大小的图像 if (图像显示.Width > 原始图像.Width) { 图像显示.Width = 原始图像.Width; this.图像显示.Image = 原始图像; } else if (图像显示.Height > 原始图像.Height) { 图像显示.Height = 原始图像.Height; this.图像显示.Image = 原始图像; } else//得到缩放后的图像 { Bitmap 显示图象 = new Bitmap(原始图像, this.图像显示.Width, this.图像显示.Height); this.图像显示.Image = 显示图象; } } else { MessageBox.Show("该文件不是图形图像文件,无法显示浏览!", "错误提示"); } })); } ACCESS 数据库 操作代码using System.Data.OleDb; //连接Access数据库 m_conn = new OleDbConnection(); m_adapter = new OleDbDataAdapter(); m_command = new OleDbCommand(); panel1.Visible = false; m_conn.Close(); SqlConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" + @".\\test.mdb"; m_conn.ConnectionString = SqlConStr; try { if (m_conn.State.Equals(ConnectionState.Closed)) { m_conn.Open(); } } catch { MessageBox.Show("对不起,连接数据库出错!", "Error!"); return; } try { m_command.Connection = m_conn; m_command.CommandText = "select * from TableName"; m_reader = m_command.ExecuteReader(); MachineIDcomboBox.Items.Clear(); while (m_reader.Read()) { //第一个字段的数据 你的存放文件路径 string tPICPathStr; tPICPathStr = m_reader.GetValue(0).ToString(); } m_conn.Close(); m_reader.Dispose(); m_command.Dispose(); 可不可以给“ChildWindow”传入参数? 报错,请问什么情况 如何读取richtextbox行前部分,后部分用messagebox显示 如何将ComboBox中的边框去掉啊,在.Net 2003中没有该属性 求救!求救!!求一个C#网吧管理软件源码!!【急!万分感谢!】 过滤掉字符串“ 79% ”? 大侠指导我动态卸装装配件啊 请问有没有sqlhelper的应用实例啊?谢谢 关于C# 基类库和 VC++ MFC的疑问 C# listview 虚拟模式更新数据,不能实时刷新,需要点击一下才能更新一次 基于WPF开发局域网聊天工具,在用udp做上线功能时遇到的问题 关于事件的问题!!
private void 显示图像(string 文件全路径名称)
{
PictureBox 图像显示 = new PictureBox();
this.BeginInvoke(new Action(() =>
{
if (文件全路径名称 != null)
{
Bitmap 原始图像 = new Bitmap(文件全路径名称);//得到原始大小的图像
if (图像显示.Width > 原始图像.Width) { 图像显示.Width = 原始图像.Width; this.图像显示.Image = 原始图像; }
else if (图像显示.Height > 原始图像.Height) { 图像显示.Height = 原始图像.Height; this.图像显示.Image = 原始图像; }
else//得到缩放后的图像
{ Bitmap 显示图象 = new Bitmap(原始图像, this.图像显示.Width, this.图像显示.Height); this.图像显示.Image = 显示图象; }
}
else { MessageBox.Show("该文件不是图形图像文件,无法显示浏览!", "错误提示"); }
}));
}
using System.Data.OleDb; //连接Access数据库
m_conn = new OleDbConnection();
m_adapter = new OleDbDataAdapter();
m_command = new OleDbCommand(); panel1.Visible = false;
m_conn.Close();
SqlConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" + @".\\test.mdb";
m_conn.ConnectionString = SqlConStr;
try
{
if (m_conn.State.Equals(ConnectionState.Closed))
{
m_conn.Open();
} }
catch
{
MessageBox.Show("对不起,连接数据库出错!", "Error!");
return; }
try
{
m_command.Connection = m_conn;
m_command.CommandText = "select * from TableName";
m_reader = m_command.ExecuteReader(); MachineIDcomboBox.Items.Clear();
while (m_reader.Read())
{
//第一个字段的数据 你的存放文件路径
string tPICPathStr;
tPICPathStr = m_reader.GetValue(0).ToString(); } m_conn.Close();
m_reader.Dispose();
m_command.Dispose();