Results 1 to 4 of 4

Thread: copying text input from one form to the other

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    copying text input from one form to the other

    Hello,

    I have 2 forms and l want to be able to copy text inputs from one form to the other form. In Visual Basic this was very easy to do. e.g. txtStudentID.Text = frmNewStudent.txtNewStudentID.text.

    But i am not sure how to do this in C#.

    Can any one tell me.

    Thanks in advance,

    Steve
    steve

  2. #2
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    assuming you instantiated the form2 and declared textbox1 of form2 as public. you can do like this.
    Code:
          Form2 f=new Form2();
          private void Form1_Load(object sender, System.EventArgs e)
          {
             f.Show();
          }
    
          private void textBox1_TextChanged(object sender, System.EventArgs e)
          {
             f.textBox1.Text=textBox1.Text;
          }

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331
    Hello,

    Thanks for you reply.

    I think l will do it the way that you said.

    Just another question, l am creating a small database application for a small library system. I have 2 tables books and students.

    The properties of students are: StudentID, Name, Address, Email. I have never done a database application using c#. Just on the student table, how can l make that oop, for example adding, updating and deleting.

    I find it easy to do it the vb way.

    Any example programs or tutorials.

    Many thanks in advance.

    Steve
    steve

  4. #4
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472
    hi there...try this.
    for the insert (adding) method.
    VB Code:
    1. /// <summary>
    2.         /// Button Save
    3.         /// </summary>
    4.         private void button1_Click(object sender, System.EventArgs e)
    5.         {
    6.            SqlConnection cn=new SqlConnection("your connection here....");
    7.            cn.Open();
    8.            String cmdText="insert into Student (StudentID,xname,address,xmail) values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "')";
    9.            SqlCommand cm=new SqlCommand(cmdText,cn);
    10.            cm.ExecuteNonQuery();
    11.            cn.Close();
    12.                      
    13.         }
    hope it helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width