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#
databasehelpquestion
7 Posts 4 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 Offline
    N Offline
    Nekshan
    wrote on last edited by
    #1

    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 hav 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:48 Tuesday 20th February, 2007

    V G S 3 Replies Last reply
    0
    • N Nekshan

      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 hav 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:48 Tuesday 20th February, 2007

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

      'all things is all right .I THINK U Assign n as date and here u declare string.so it might get error. 'string d = form1_.n; ' used like this datetime n = form1.n; '& u used from1 is the name of form right?

      N 1 Reply Last reply
      0
      • N Nekshan

        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 hav 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:48 Tuesday 20th February, 2007

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        I see three errors in your code. 1. You have declared the reference form1_ as a reference to a Form object, not a form1 object. Therefore you only have access to the members of the base class, none of the members of the inherited class. 2. You are creating a completely new instance of form1, that means that it's separate from the instance that already exists. This in turn means that the n member has not been set for that instance. 3. You are executing an insert query and expect it to return data. The result from an insert query is empty, so the ExecuteScalar method will return null. This will be converted to DateTime.MinValue by the Convert.ToDateTime call.

        --- single minded; short sighted; long gone;

        1 Reply Last reply
        0
        • N Nekshan

          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 hav 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:48 Tuesday 20th February, 2007

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

          Take a look on it http://www.codeproject.com/useritems/pass\_data\_between\_forms.asp

          Thanks and Regards Sandeep

          N 1 Reply Last reply
          0
          • V virendra patel

            'all things is all right .I THINK U Assign n as date and here u declare string.so it might get error. 'string d = form1_.n; ' used like this datetime n = form1.n; '& u used from1 is the name of form right?

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

            datetime n = form1.n; -- Not Working:error on 'n'. Nekshan.

            1 Reply Last reply
            0
            • S Sandeep Akhare

              Take a look on it http://www.codeproject.com/useritems/pass\_data\_between\_forms.asp

              Thanks and Regards Sandeep

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

              Thanx Sandeep. The project u suggested is really nice. Nekshan.

              S 1 Reply Last reply
              0
              • N Nekshan

                Thanx Sandeep. The project u suggested is really nice. Nekshan.

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

                My Pleasure :)

                Thanks and Regards Sandeep

                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