Thread: I have problem!!!

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    31

    I have problem!!!

    Hi
    Please I have a problem
    I have created a program deals with data base for ( cars showroom), I will illustrate the problem
    Suppose form (A) has the connection & data grid and every think necessary, and form (B) which used for inserting cars for instance. When the insertion operation complete the data grid don't update but the actual data has been updated in the data base so I have to close the form (A) then run it again and after that the changes happened ( note : my program working but the data grid don't update immediately )
    I must mention that I have use the object technique

    So when I say open form (B) for insert
    CODE 1
    Code:
    Form ptr= new B();
    B.visible=true;
    and in the form (B) after inserting (save button)
    CODE 2
    Code:
    A insertptr= new A();
    // this function do the insert,delelte…….
    insertptr.SQLserver("SQL statement",insertptr.sqlConnection1);
    I have tried to solve this problem by using updeta(), refresh() , but it didn't work
    Also I have do this , I created public function in form (A)
    CODE 3
    Code:
    public void loadfun()
    		{
    	
    			this.sqlConnection1.Open();
    			this.dataSet1.Clear();
    			this.sqlDataAdapter1.SelectCommand.CommandText = "SELECT * FROM       CarSpecifications ORDER BY CarName,Class,Model,SpecificationId";
    			this.sqlDataAdapter1.Fill(dataSet1,"CarSpecifications");
    			this.sqlConnection1.Close();
    		
    
    			dataGrid1.SetDataBinding(dataSet1,"CarSpecifications");
    and in the load event for form (A)
    CODE 4
    Code:
    		private void Cars_Showroom_Load(object sender, System.EventArgs e)
    		{
    			loadfun();
    
    		}
    and in the code number 2 see above I have put
    Code:
    	A New_Specification = new New_Specification();
    	New_Specification.loadfun();
    but unfortunately it didn't work, the strange is when I call it in the load it works, when I call it in anywhere form Form (A) it works, but when I call it from Form(B) it works but the update don't happen immediately I must restart the form or I must call that function (loadfun) from the form (A) which the function located.

    i hope that I could explain the problem very well so that u can help me

    Note: I don't have any syntax error and I am very sure form code coz the program work properly .

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    If the function works when you call it from Form A, then in Form A put it after the ShowDialog of Form B like this:


    (in buttonpress or something)

    FormB b = new FormB();

    FormB.ShowDialog();

    loadfun();
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    31
    Thanks Mr. nvoigt

    But I think this will not solve my problem because ur opening a new form (A | B) and what I want is to update the form (A | B ) itself without creating new form. Also I think closing the form and then open it again more efficient than create new one, but this will cause losing the information that have been written in the ( textbox) .

    Again thank u very much Mr. nvoigt

    If anybody has any answer please submit it immediately

    thanks

  4. #4
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356
    have u tried the onFocus event ??in the OnFocus event of form a just read back the data into the dataGrid...
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    31
    no it doesn't work

    please can u help me in another way

    i want to close Form A from Form B how can do that coz i have tried this

    Code:
    // what i want is to close Form A
    // all this in Form B
    A n = new A();
    
    n.close();
    
    // also i have tried this 
    
    n.visible=false;
    but the striange is when i do this
    Code:
    // what i want is to close Form A
    // all this in Form B
    A n = new A();
    
    n.visible=true;
    it opens new Form A , My Q is why it works with open and doesn't work the close method???

  6. #6
    Registered User
    Join Date
    Apr 2003
    Posts
    31
    Hi
    i thank i have understood the problem but still can not be able to solve it
    if i want to change any thing in Form A from the Form B i must get the pointer that points to the actual Form A suppose we
    create the Form A in Form Q
    Code:
    // all in Form Q 
    A n = new A();
    n.show();
    so the pointer n holds the handle of the Form A
    so if i want to change Form A in(from) the Form B I must get the value of n

    i know it confuses but please try to help meeeeeeeeeeeee

    how can I get the value of n then use it in form B

  7. #7
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Most controls have a parent. I'm not sure if forms have a parent form, I'm not at a development computer right now. If they don't, make your constructor of form B take an agrument of type A.

    in FormA:

    FormB x = new FormB( this );
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  8. #8
    Registered User
    Join Date
    Apr 2003
    Posts
    31
    hi my friend
    thank u very much for help but this satement generates syntax error

  9. #9
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    I'll be able to help you if you post the code for the forms, all of it except maybe your calculations etc.

  10. #10
    Registered User
    Join Date
    Apr 2003
    Posts
    31
    thank u Mr. speedy5
    but i think there is no benefit from posting the code
    also it is too large
    i have explained the problem very well above
    but if u want, i will send it in text file to your E-mail

    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM