Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. User Control taking up too much resources

User Control taking up too much resources

Scheduled Pinned Locked Moved C#
comhelpquestion
12 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xiaowenjie
    wrote on last edited by
    #1

    hi, i've added user control onto my main form. but when i run my program, i realise it eats up a lot of resources. my com becames very lag. what's the problem? Chris

    S 1 Reply Last reply
    0
    • X xiaowenjie

      hi, i've added user control onto my main form. but when i run my program, i realise it eats up a lot of resources. my com becames very lag. what's the problem? Chris

      S Offline
      S Offline
      sreejith ss nair
      wrote on last edited by
      #2

      What sort of user control that you are using ? i mean what it does ? Sreejith Nair [ My Articles ]

      X 1 Reply Last reply
      0
      • S sreejith ss nair

        What sort of user control that you are using ? i mean what it does ? Sreejith Nair [ My Articles ]

        X Offline
        X Offline
        xiaowenjie
        wrote on last edited by
        #3

        i've this main window form where it contains 4 user control. each of this user control connects to the database. after i added these user control onto my main form and run my program, my com became very lag. Chris

        S 1 Reply Last reply
        0
        • X xiaowenjie

          i've this main window form where it contains 4 user control. each of this user control connects to the database. after i added these user control onto my main form and run my program, my com became very lag. Chris

          S Offline
          S Offline
          sreejith ss nair
          wrote on last edited by
          #4

          Try to create a class which do database communication insted of user controls. And try to get the reference of class which have the implimentation part of data access into your user control. Sreejith Nair [ My Articles ]

          X 3 Replies Last reply
          0
          • S sreejith ss nair

            Try to create a class which do database communication insted of user controls. And try to get the reference of class which have the implimentation part of data access into your user control. Sreejith Nair [ My Articles ]

            X Offline
            X Offline
            xiaowenjie
            wrote on last edited by
            #5

            ok i try tt. thanks ;) chris

            1 Reply Last reply
            0
            • S sreejith ss nair

              Try to create a class which do database communication insted of user controls. And try to get the reference of class which have the implimentation part of data access into your user control. Sreejith Nair [ My Articles ]

              X Offline
              X Offline
              xiaowenjie
              wrote on last edited by
              #6

              hi, i've managed to put the database connection coding into a separate class. namespace WindowsApplication2 { public class db1 { public OleDbConnection conn; public string display_SQL; public OleDbCommand display_cmd; public OleDbDataAdapter display_adapter; public DataSet display_ds; public db1() { conn = new System.Data.OleDb.OleDbConnection(); conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data source =C:\Documents and Settings\Desktop\WindowsApplication2\bin\Debug\mydbms.mdb"; display_SQL = "SELECT * FROM tblYear"; display_cmd = new System.Data.OleDb.OleDbCommand (display_SQL, conn); display_adapter = new System.Data.OleDb.OleDbDataAdapter(display_cmd); display_ds = new System.Data.DataSet(); display_adapter.Fill(display_ds,"tblYear"); } } i'm not really good in using separate class.so how do we do these same connection into a function in this same class instead of doing it in the constructor? and how do we call that function from a button? anw is there a wweb site where they teach about windows classes which may assist more?? Chris

              1 Reply Last reply
              0
              • S sreejith ss nair

                Try to create a class which do database communication insted of user controls. And try to get the reference of class which have the implimentation part of data access into your user control. Sreejith Nair [ My Articles ]

                X Offline
                X Offline
                xiaowenjie
                wrote on last edited by
                #7

                sorry i was wrong. :( i don't know how to call the function from a different class if i do a database connection in that function and not in the constructor of the separate class?? is it public void connection(){} or ??

                K 1 Reply Last reply
                0
                • X xiaowenjie

                  sorry i was wrong. :( i don't know how to call the function from a different class if i do a database connection in that function and not in the constructor of the separate class?? is it public void connection(){} or ??

                  K Offline
                  K Offline
                  Ketty Avashia
                  wrote on last edited by
                  #8

                  Handle it on button click. create an object of ur class Class DBConnection { public void Connect() { ....do ur code; } } Button1_Click() { DbConnection DbConn = new DBConnection(); DBConn.Connect(); } U can pass and return parameters too to this Connect Function; I hope I am up to ur expection...:-D Ketty

                  X 1 Reply Last reply
                  0
                  • K Ketty Avashia

                    Handle it on button click. create an object of ur class Class DBConnection { public void Connect() { ....do ur code; } } Button1_Click() { DbConnection DbConn = new DBConnection(); DBConn.Connect(); } U can pass and return parameters too to this Connect Function; I hope I am up to ur expection...:-D Ketty

                    X Offline
                    X Offline
                    xiaowenjie
                    wrote on last edited by
                    #9

                    hey thanks a lot. but i've got one question:-D let say i've got this form which has a textbox and dataGrid. then i will create a separate class like wat u taught me. if my SQl statement goes like this: "Select * From Table Where Col1 ='" + textBox1.Text + "'";..... how should i pass in the textBox1.Text value to this connection function?? private void button1_Click(object sender, System.EventArgs e) { db1 a = new db1(); dataGrid1.DataSource = ?? dataGrid1.DataMember = ?? } Class DBConnection { public void Connect() { string SQL = "Select * From Table Where Col1 ='" + textBox1.Text + "'"; //?? ....do ur code; } } Chris

                    K 1 Reply Last reply
                    0
                    • X xiaowenjie

                      hey thanks a lot. but i've got one question:-D let say i've got this form which has a textbox and dataGrid. then i will create a separate class like wat u taught me. if my SQl statement goes like this: "Select * From Table Where Col1 ='" + textBox1.Text + "'";..... how should i pass in the textBox1.Text value to this connection function?? private void button1_Click(object sender, System.EventArgs e) { db1 a = new db1(); dataGrid1.DataSource = ?? dataGrid1.DataMember = ?? } Class DBConnection { public void Connect() { string SQL = "Select * From Table Where Col1 ='" + textBox1.Text + "'"; //?? ....do ur code; } } Chris

                      K Offline
                      K Offline
                      Ketty Avashia
                      wrote on last edited by
                      #10

                      In that case private void button1_Click(object sender, System.EventArgs e) { db1 a = new db1(); dataGrid1.DataSource = Connect(txtbox1.text); dataGrid1.DataMember = ?? } Class DBConnection { public DataSet Connect(String TextVal) { DataSet ds = new DataSet(); string SQL = "Select * From Table Where Col1 ='" + TextVal + "'"; //?? ....do ur code; Return ds } } Is that fine now ;) Ketty

                      X 1 Reply Last reply
                      0
                      • K Ketty Avashia

                        In that case private void button1_Click(object sender, System.EventArgs e) { db1 a = new db1(); dataGrid1.DataSource = Connect(txtbox1.text); dataGrid1.DataMember = ?? } Class DBConnection { public DataSet Connect(String TextVal) { DataSet ds = new DataSet(); string SQL = "Select * From Table Where Col1 ='" + TextVal + "'"; //?? ....do ur code; Return ds } } Is that fine now ;) Ketty

                        X Offline
                        X Offline
                        xiaowenjie
                        wrote on last edited by
                        #11

                        hi, thanks i managed to do it. but i got another problem.. i'v e got this class.. this is the function class test { public void test ( string LD ) { LD = "haha"; } } // end of class test class Form1:System.Windows.Forms.Form { private void btnConvert_Click(object sender, System.EventArgs e) { string date; cL.CalendarConversion(date); // but date is null } }//end of class form1 i can't pass the value of LD from class test to date from class Form1.. why? Chris

                        K 1 Reply Last reply
                        0
                        • X xiaowenjie

                          hi, thanks i managed to do it. but i got another problem.. i'v e got this class.. this is the function class test { public void test ( string LD ) { LD = "haha"; } } // end of class test class Form1:System.Windows.Forms.Form { private void btnConvert_Click(object sender, System.EventArgs e) { string date; cL.CalendarConversion(date); // but date is null } }//end of class form1 i can't pass the value of LD from class test to date from class Form1.. why? Chris

                          K Offline
                          K Offline
                          Ketty Avashia
                          wrote on last edited by
                          #12

                          class test { public string test ( string LD ) { LD = "haha"; } } // end of class test class Form1:System.Windows.Forms.Form { private void btnConvert_Click(object sender, System.EventArgs e) { string date; test ts = new test(); date = ts.test(); cL.CalendarConversion(date); // date is not null now } }//end of class form1 Is this that u wanted? :confused: Ketty

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups