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. a query [modified]

a query [modified]

Scheduled Pinned Locked Moved C#
questiondatabasehelp
11 Posts 5 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.
  • N Nekshan

    private void logout_Click(object sender, EventArgs e) { conn.Open(); string strQury = ""; strQury = "insert into dashboarddealerlogin (logoutdatetime) values '(" + DateTime.Now + ")'"; SqlCommand cm = new SqlCommand(strQury, conn); int n = Convert.ToInt32(cm.ExecuteScalar()); } I have written this code in form1.cs and i need to write it there only on 'logout_click'. Now i want to use this 'int n' in a function in form2.cs of same project: funEntrylogin(m, i, tb_id.Text, tb_pswd.Text, DateTime.Now,n); but here it is giving error on 'n',if i write the above code, as 'n' is not declared in form2.cs. How can i declare this 'int n' of form1 in form2? How can i do this? thanx. nekshan. -- modified at 1:57 Tuesday 20th February, 2007

    V Offline
    V Offline
    virendra patel
    wrote on last edited by
    #2

    'form1 ' define this n globally on top of form1 Public n As Integer ' form2 ' create objec to from1 in from2 Dim f1 As New Form1 ' used like string s = f1.n 'this declaration is vb convert it to c# ok.

    N 1 Reply Last reply
    0
    • N Nekshan

      private void logout_Click(object sender, EventArgs e) { conn.Open(); string strQury = ""; strQury = "insert into dashboarddealerlogin (logoutdatetime) values '(" + DateTime.Now + ")'"; SqlCommand cm = new SqlCommand(strQury, conn); int n = Convert.ToInt32(cm.ExecuteScalar()); } I have written this code in form1.cs and i need to write it there only on 'logout_click'. Now i want to use this 'int n' in a function in form2.cs of same project: funEntrylogin(m, i, tb_id.Text, tb_pswd.Text, DateTime.Now,n); but here it is giving error on 'n',if i write the above code, as 'n' is not declared in form2.cs. How can i declare this 'int n' of form1 in form2? How can i do this? thanx. nekshan. -- modified at 1:57 Tuesday 20th February, 2007

      S Offline
      S Offline
      Sandeep Akhare
      wrote on last edited by
      #3

      Hi Use Query string or you can put this varaible in the session and get it from the session on next page

      Thanks and Regards Sandeep

      N 1 Reply Last reply
      0
      • N Nekshan

        private void logout_Click(object sender, EventArgs e) { conn.Open(); string strQury = ""; strQury = "insert into dashboarddealerlogin (logoutdatetime) values '(" + DateTime.Now + ")'"; SqlCommand cm = new SqlCommand(strQury, conn); int n = Convert.ToInt32(cm.ExecuteScalar()); } I have written this code in form1.cs and i need to write it there only on 'logout_click'. Now i want to use this 'int n' in a function in form2.cs of same project: funEntrylogin(m, i, tb_id.Text, tb_pswd.Text, DateTime.Now,n); but here it is giving error on 'n',if i write the above code, as 'n' is not declared in form2.cs. How can i declare this 'int n' of form1 in form2? How can i do this? thanx. nekshan. -- modified at 1:57 Tuesday 20th February, 2007

        N Offline
        N Offline
        NanaAM
        wrote on last edited by
        #4

        Store the value in a hidden html field. And user server.transfer to go to other form and in form2 use the request object to get the value of hidden field from form1

        Nana

        N 1 Reply Last reply
        0
        • S Sandeep Akhare

          Hi Use Query string or you can put this varaible in the session and get it from the session on next page

          Thanks and Regards Sandeep

          N Offline
          N Offline
          Nekshan
          wrote on last edited by
          #5

          session? i m doing windows programming. can i use session in windows programming? i dont think so.. if can... how? Thank You. nekshan.

          S 1 Reply Last reply
          0
          • N NanaAM

            Store the value in a hidden html field. And user server.transfer to go to other form and in form2 use the request object to get the value of hidden field from form1

            Nana

            N Offline
            N Offline
            Nekshan
            wrote on last edited by
            #6

            i m doing windows programming.

            V 1 Reply Last reply
            0
            • N Nekshan

              session? i m doing windows programming. can i use session in windows programming? i dont think so.. if can... how? Thank You. nekshan.

              S Offline
              S Offline
              Sandeep Akhare
              wrote on last edited by
              #7

              Sorry Boss You should mension that

              Thanks and Regards Sandeep

              1 Reply Last reply
              0
              • N Nekshan

                i m doing windows programming.

                V Offline
                V Offline
                virendra patel
                wrote on last edited by
                #8

                ya wind prog code is sent u

                1 Reply Last reply
                0
                • V virendra patel

                  'form1 ' define this n globally on top of form1 Public n As Integer ' form2 ' create objec to from1 in from2 Dim f1 As New Form1 ' used like string s = f1.n 'this declaration is vb convert it to c# ok.

                  N Offline
                  N Offline
                  Nekshan
                  wrote on last edited by
                  #9

                  In form1,i defined it like : namespace WindowsApplication1 { public partial class form1 : Form { public DateTime n; SqlConnection conn = new SqlConnection("Data Source=PROGRAMER;Initial Catalog=...."); ..... } In form2,i made object of form1: System.Windows.Forms.Form form1_ = new form1(); string d = form1_.n; -- BUT it is giving error on 'n' here, 'n' doesnot come on click of'.' after form1_ I have used it like this in form1: private void button1_Click(object sender, EventArgs e) { conn.Open(); string strQury = ""; strQury = "insert into dashboarddealerlogin (logoutdatetime) values '(" + DateTime.Now + ")'"; SqlCommand cm = new SqlCommand(strQury, conn); n = Convert.ToDateTime(cm.ExecuteScalar()); } Is my global declaration of 'n' still not proper? Thank You. Nekshan. -- modified at 2:51 Tuesday 20th February, 2007

                  1 Reply Last reply
                  0
                  • N Nekshan

                    private void logout_Click(object sender, EventArgs e) { conn.Open(); string strQury = ""; strQury = "insert into dashboarddealerlogin (logoutdatetime) values '(" + DateTime.Now + ")'"; SqlCommand cm = new SqlCommand(strQury, conn); int n = Convert.ToInt32(cm.ExecuteScalar()); } I have written this code in form1.cs and i need to write it there only on 'logout_click'. Now i want to use this 'int n' in a function in form2.cs of same project: funEntrylogin(m, i, tb_id.Text, tb_pswd.Text, DateTime.Now,n); but here it is giving error on 'n',if i write the above code, as 'n' is not declared in form2.cs. How can i declare this 'int n' of form1 in form2? How can i do this? thanx. nekshan. -- modified at 1:57 Tuesday 20th February, 2007

                    N Offline
                    N Offline
                    NanaAM
                    wrote on last edited by
                    #10

                    Declare a var in Form1 and not in method. public static int n; set the value in form1's method. Now in form2 access it as Form1.n u will get the value.

                    Nana

                    1 Reply Last reply
                    0
                    • N Nekshan

                      private void logout_Click(object sender, EventArgs e) { conn.Open(); string strQury = ""; strQury = "insert into dashboarddealerlogin (logoutdatetime) values '(" + DateTime.Now + ")'"; SqlCommand cm = new SqlCommand(strQury, conn); int n = Convert.ToInt32(cm.ExecuteScalar()); } I have written this code in form1.cs and i need to write it there only on 'logout_click'. Now i want to use this 'int n' in a function in form2.cs of same project: funEntrylogin(m, i, tb_id.Text, tb_pswd.Text, DateTime.Now,n); but here it is giving error on 'n',if i write the above code, as 'n' is not declared in form2.cs. How can i declare this 'int n' of form1 in form2? How can i do this? thanx. nekshan. -- modified at 1:57 Tuesday 20th February, 2007

                      R Offline
                      R Offline
                      Russell Jones
                      wrote on last edited by
                      #11

                      you can set the variable up as a public static property of some class. This isn't the best technique as it is very similar to having a global variable. You could set a property on form2 or pass the value of n into form2 in its constructor, I would rather do one of these depending on how your application is coded. Russell

                      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