我在一个form2中连接数据库,做了个用户密码进入窗口,正确就可以进入form1,但我想在另一个form1显示在form2中取得的那个用户名出来,应如何做,好高们帮帮忙好吗?
解决方案 »
- 解码问题,试了所有方法,都不能解码,请问为什么
- 求救 如何将excel中的数据写入access数据库中
- C#程序在WIN2003下编译运行正常,在XP下安装后运行提示错误
- DX控件高手请帮帮我.gridcontrol 绑定list,关于更改列名,或者隐藏列,谢谢大家
- 求学过C#的大牛分享一下看哪些书
- 怎样在程序中获得sqlServer服务器上所有的数据库名称?(过滤掉系统数据库)
- 大家好,我在mdi的父窗口的工作区想显示一个图片,我是这样做的,放了一个picturebox,但这样子窗口就显示不出来了
- 传值
- 从具体化“System.Decimal”类型到“System.Int32”类型的指定强制转换无效
- [请教]如何在web application 中使用C#完成SharePoint任务?
- datagrid 如何改变显示数据的格式
- ======ASP.NET的无组件上传问题fileup.PostedFile.FileName得不到文件名,解决了立即给分============
先做一个发分发消息的类:using System;namespace Community
{
/// <summary>
/// Notify 的摘要说明。
/// </summary>
public class Notify
{
protected static Notify m_notify=null;
public delegate void NotifyEvent(object sender,NotifyEventArgs e);
public event NotifyEvent OnNotifyEvent;
public Notify()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static Notify Instance
{
get
{
if (m_notify == null)
m_notify = new Notify();
return m_notify; }
} public void SendMessage(int code, string message)
{
NotifyEventArgs e = new NotifyEventArgs(code, message);
if ( OnNotifyEvent != null)
OnNotifyEvent(this, e);
}
} ///////////
public class NotifyEventArgs:System.EventArgs
{
protected int m_nCode;
protected string m_strMessage = string.Empty;
public NotifyEventArgs()
{
}
public NotifyEventArgs(int code,string message)
{
m_nCode=code;
m_strMessage=message;
}
public int Code
{
get { return m_nCode;}
set { m_nCode = value;}
}
public string Message
{
get { return m_strMessage;}
set
{
m_strMessage = value;
if (m_strMessage == null)
m_strMessage = string.Empty;
}
}
#region Common Infomation
public const int ToAnimation= 1;
public const int ToDump=2;
// public const int CompanyInfo = 1;
// public const int ProjectInfo = 2;
// public const int TaskInfo = 3;
// public const int Opportunity = 4;
// public const int Contactor = 5;
// public const int EmployeeInfo = 6;
// public const int DepartmentInfo = 7;
// public const int AdvCityInfo = 8;
#endregion
}
}
{
int i=Convert.ToInt32(e.Message );
if(e.Code ==NotifyEventArgs.ToForm1)
{
MessageBox.show("我得到了Form2的值");
}
}按这种方式,你自已扩展!!我的程序都是这么做的
Notify.Instance .SendMessage (Community.NotifyEventArgs .ToForm1,"这是Form2的信息");
写好委托事件,在form2 中改变数据库时发送消息到form1,此时form1接收到form2中的消息,然后开始执行你所写的委托事件,你在委托事件中重取数据库就可以得到最新的用户信息。
http://blog.csdn.net/zhzuo/archive/2004/04.aspx
这么写。
Form2 good=new Form2//good自定义
good.v=user;//v首先要在Form2里面做全局变量如: pubilc srting v; //user是你用户名筐的值
good.show();//打开
在给你个思路。
在连接数据时你不是要进行IF判断是否用户是否正确!加在正确后进入另个连接里面
如:
if (myReader.Read()==true)
{
Form3 mscr=new Form3();
this.Hide ();
mscr.shuju=accNo;
mscr.Show();
}
else{}