使用查询将值从一页传递到另一页 [英] passing values from one page to another using query

查看:134
本文介绍了使用查询将值从一页传递到另一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi..me sakshi.
我正在使用vs-2005和ms sql创建一个c#.net Windows应用程序.

我的问题是-

我有一个数据表,其中包含年,州,区,tehsil等.

在登录页面上,我必须选择年份,并从组合框中选择与特定年份相对应的状态.

在form2(登录后我要去的地方)上,有一个区域,tehsil的组合.

我希望当我选择年份时,在登录时说明并提交表格,然后在form2上,组合中应该只存在与我在登录页面中选择的特定年份和州有关的区域.

请帮助我....

谢谢.

hi..me sakshi.
i am creating a c#.net windows application with vs-2005 and ms sql.

My problem is--

I have a datatable having year,state,district,tehsil etc.

At login page i have to select year,state corrosponding to particular year from combobox.

on form2(where i go after login) there is a combo for district,tehsil.

i want that when i select year,state at login and submit the form then on form2 there should be districts in combo only related to the particular year and state which i have selected at login page.

please help me....

thanks.

推荐答案



有多种方法可以做达,这是其中一种方法:

*创建2个状态STATE&在Form2.cs中设置YEAR,以在Form1.cs中设置值

Hi,

there are many ways to do tat and here is one of the way:

* Create 2 properties STATE & YEAR in Form2.cs to set the values in Form1.cs

string stat;
     int yr;
     public string STATE
     {
         get { return stat; }
         set { stat = value; }
     }
     public int YEAR
     {
         get { return yr; }
         set { yr = value; }
     }



*在Form1.cs中为Form2创建对象f2,并设置State&从组合框值中选择后的年份:




* Create an object f2 for Form2 in Form1.cs and set the values of State & Year as after selecting from combobox values:


f2.STATE = cmbstate.SelectedItem.ToString();
     f2.YEAR = int.Parse(cmbyear.SelectedItem.ToString());




*现在,您可以使用这些值并可以在Form2.cs中按要求进行查询.




* Now u can use these values and can query as per requirements in Form2.cs.


您需要做的是在form2中具有一些属性,并在初始化时填充它们. >
因此,在form1(登录)中,您调用form2.

Form2将具有以下代码...

What you need to do is have the some properties in form2 and populate them on intialise.

So in form1 (Login) you call form2.

Form2 will have code as follows...

public Form2()
       {
           InitializeComponent();
       }



您需要做的就是添加一个属性(或者只是一个变量,取决于您要使用该值的位置的多少)



What you need to do is add a property (Or just a variable, depends how many places you want to use the value)

private string selectedYear;
       private string selectedCountry;

       public Form2(string p_selectedYear, string p_selectedCountry)
       {
           selectedYear = p_selectedYear;
           selectedCountry = p_selectedCountry;
           InitializeComponent();
       }



差不多就可以了.

当您从登录"表单调用Form2时....



And thats pretty much it.

When you call the Form2 from the Login form....

private void button1_Click(object sender, EventArgs e)
      {
          Form2 newLogin = new Form2("2010", "United Kingdom");
 newLogin.Show();
      }


,您可以在目标页面ex:year和state中创建公共属性.

从源页面访问这些属性,然后分配值.在表格2上,您可以使用年份和州值.


public int _year;
公共诠释年
{
获取
{
返回_year;
}


设置

{
_year =值;
}
}


同样为状态做.



在form2中,访问year属性并为其指定year的值.
you can create a public property in destination page ex:year and state.

Access these properties from the source page and assign then the values. on on form 2 you can use the year and state values.


public int _year;
public int year
{
get
{
return _year;
}


set

{
_year = value;
}
}


similarly do it for state.



in form2 access the year property and assign it the value of the year.


这篇关于使用查询将值从一页传递到另一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆