Hello Everybody,

I use different forms....I want to send a value like form1 to form2.for example textbox1.text value, I want to send it to myStr in form2. I tried public static but I could not solve it. Also another problem is this. There is 3 forms. If form1 sends a value to form3 so x class is working, if form2 sends a value to form3 so y class is working...x and y my functions which is getting data from mssql db.
My first problem global variable antoher one different value. I think I need to like this Form1(string, string)

Thank you in attend....

Well if you are opening form2 from form1, then it can be done quite easily.
Simply create a public class level variable in form2:

public string myStr;

In form1, use this to open up form2:

form1 f = new form1();
f.myStr = textbox1.text;
f.show();

could'nt really understand the 2nd half of your message. x and y are classes or functions? what exactly are you trying to do there?

x functions is this :

monthlyWorks(infoTB.Text, thisMounth);


public DataSet monthlyWorks(string IsyeriId, string month)
{
Service();
string str;
str = string.Format("SELECT Kartno,IsyeriId,Tarih,Tutar,IslemTipi,KazandirilanPuan,HarcattirilanPuan FROM IslemTablosu WHERE IsyeriId='{0}' and MONTH(Tarih)='{1}' ", IsyeriId, ay);
SqlDataAdapter adapter = new SqlDataAdapter(str, connection);
DataSet dataset = new DataSet();
adapter.Fill(dataset);
return dataset;
}

y function is also same but it does not get IsyeriId, it gets CardNo...

My problem is form1 sends IsyeriId to form3 whenever push a Islem button in form1. form2 sends CardNo to form3 whenever push a Islem button in form2.

If you call a function in form2 from form1 then you can pass parameters

Otherwise I have used the Program class which is automatically generated by Visual Studio when you create a windows application. Everything in there is usually public static and then you can pass the variable to program from form 1 before form 2 executes it's function and then in form 2's function you get this variable from Program again. Or something similar of course...

Thank you so much Jatin, I solved this. also thank you Ryuslash but I didnt understand you so much. Please give me example or tell me different it...

x functions is this :

monthlyWorks(infoTB.Text, thisMounth);

public DataSet monthlyWorks(string IsyeriId, string month)
        {
            Service();
            string str;
            str = string.Format("SELECT Kartno,IsyeriId,Tarih,Tutar,IslemTipi,KazandirilanPuan,HarcattirilanPuan FROM IslemTablosu WHERE IsyeriId='{0}' and MONTH(Tarih)='{1}' ", IsyeriId, ay);
            SqlDataAdapter adapter = new SqlDataAdapter(str, connection);
            DataSet dataset = new DataSet();
            adapter.Fill(dataset);
            return dataset;
        }

y function is also same but it does not get IsyeriId, it gets CardNo...

My problem is form1 sends IsyeriId to form3 whenever push a Islem button in form1. form2 sends CardNo to form3 whenever push a Islem button in form2.

I'm not sure I understand the problem as stated. I see you are trying to communicate between forms, but what exactly is not working?

Thank you DdoubleD I solved it ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.