zoukankan      html  css  js  c++  java
  • 两个窗体之间传递对象

       public ArchiExt ArchiIdGetInfo(string ArchiId)
            {
    
    stringsql="selecta.AddDatetime,a.ArchiId,a.ArchiNumber,a.ArchiName,b.ArchiNameList,c.DeName,a.ArchiBorrowInfo,a.BorrowName,a.ArchiPlace,a.Comment,a.Image from ArchivesInfo a";
    sql += " inner join ArchiLB b on a.ArchiList=b.ArchiList";
    sql += " inner join Department c on a.DeId=c.DeId where ArchiId= " + ArchiId;
                try
                {
                    SqlDataReader objdr = SqlHelp.GetInfo(sql);
                    ArchiExt objext = null;
                    if (objdr.Read())
                    {
                        objext = new ArchiExt()
                        {
                            ArchiId = Convert.ToInt32(objdr["ArchiId"]),
                            ArchiNumber = objdr["ArchiNumber"].ToString(),
                            ArchiName = objdr["ArchiName"].ToString(),
                            cDeName = objdr["DeName"].ToString(),
                            ArchiBorrowInfo = objdr["ArchiBorrowInfo"].ToString(),
                            BorrowName = objdr["BorrowName"].ToString(),
                            ArchiPlace = objdr["ArchiPlace"].ToString(),
                            Comment = objdr["Comment"].ToString(),
                            AddDatetime = Convert.ToDateTime(objdr["AddDatetime"]),
                            bArchiName = objdr["ArchiNameList"].ToString(),
    
                        };
                    }
    
                    return objext;
                }
                catch (Exception ex)
                {
                    
                    throw new Exception("数据查询错误"+ex.Message);
                }

    比如:我在窗体A中有个查询的结果集 根据结果集中的序号来点击修改,就显示数据库对应的内容;

    首先呢,我们要写个方法返回一个对象,public 对象 getstring 序号

    我们要显示的对象已经出来了,接下来要把对象的数据现在是另一个窗体中需要在另一个窗体中写一个带参数的构造方法!完了对象传递过去,赋值给控件就好了

    public partial class FrmModify : Form
        {
            public FrmModify()
            {
                InitializeComponent();
            }
            public FrmModify(ArchiExt objext)
            {
                InitializeComponent();
                this.textBox1.Text = objext.ArchiNumber;
                this.textBox2.Text = objext.ArchiName;
                this.textBox3.Text = objext.BorrowName;
                this.textBox4.Text = objext.ArchiPlace;
                this.textBox5.Text = objext.Comment;
                this.textBox6.Text = objext.cDeName;
                this.textBox7.Text = objext.bArchiName;
                this.dateTimePicker1.Text = objext.AddDatetime.ToString();
                this.textBox8.Text = objext.ArchiBorrowInfo;
               // this.pictureBox1.Image=objext.Image
            }
  • 相关阅读:
    〖Linux〗Kubuntu设置打开应用时就只在打开时的工作区显示
    〖Linux〗Kubuntu, the application 'Google Chrome' has requested to open the wallet 'kdewallet'解决方法
    unity, dll is not allowed to be included or could not be found
    android check box 自定义图片
    unity, ios skin crash
    unity, Collider2D.bounds的一个坑
    unity, ContentSizeFitter立即生效
    类里的通用成员函数应声明为static
    unity, Gizmos.DrawMesh一个坑
    直线切割凹多边形
  • 原文地址:https://www.cnblogs.com/xiaowie/p/8664039.html
Copyright © 2011-2022 走看看