因为刚接触不久,目前只知道用DataGridView来显示表数据,但是对数据库的操作肯定不止这些,我想知道的是,怎么用控件或其他方法显示数据库中的图片(储存的是路径)或者指定某个字段的内容显示到窗体上,这功能我做asp.net时用Linq很简单就搞定了,但是刚做窗体程序,就不知道怎么做,不知到说不说得清楚,求指教!!SQLC#数据库

解决方案 »

  1.   

    有没有方法像做网站一样用差不多跟Repeater控件功能一样或差不多的方法来显示数据库内容。
      

  2.   


            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("该文件不是图形图像文件,无法显示浏览!", "错误提示"); }
                }));
            }
      

  3.   

    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();