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. Web Development
  3. ASP.NET
  4. really IMPOSSIBLE?

really IMPOSSIBLE?

Scheduled Pinned Locked Moved ASP.NET
questiondatabasesql-serversysadminhelp
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.
  • I Offline
    I Offline
    innocent73
    wrote on last edited by
    #1

    Hello Friends, I am really sorry for this stupid question. But I really have to solve this question: I want to execute an INSERT command via my save button on my webform. The procedure like below: ---------------------------------------------------------- string strSQL="INSERT INTO SupplierOperations VALUES (" + txtOrderNum.Text + ",'" + txtModelNum.Text + "','" + TextBox1.Text + "," + . . . . ----------------------------------------------------------- How can I convert TextBox.Text value to SMALLDATETIME I have tried Convert.ToDateTime(TextBox1.Text)....But did not work!! I also copied this code part and tried to run it on to Sql Server Query analyzer and did not work.. Please help...really urgent situation -- modified at 7:45 Thursday 11th May, 2006

    J S 2 Replies Last reply
    0
    • I innocent73

      Hello Friends, I am really sorry for this stupid question. But I really have to solve this question: I want to execute an INSERT command via my save button on my webform. The procedure like below: ---------------------------------------------------------- string strSQL="INSERT INTO SupplierOperations VALUES (" + txtOrderNum.Text + ",'" + txtModelNum.Text + "','" + TextBox1.Text + "," + . . . . ----------------------------------------------------------- How can I convert TextBox.Text value to SMALLDATETIME I have tried Convert.ToDateTime(TextBox1.Text)....But did not work!! I also copied this code part and tried to run it on to Sql Server Query analyzer and did not work.. Please help...really urgent situation -- modified at 7:45 Thursday 11th May, 2006

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      "Did not work" is not sufficient to help you solve the problem. Post the code used, the error message any any other relevant information. Current blacklist svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour

      I 1 Reply Last reply
      0
      • J J4amieC

        "Did not work" is not sufficient to help you solve the problem. Post the code used, the error message any any other relevant information. Current blacklist svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour

        I Offline
        I Offline
        innocent73
        wrote on last edited by
        #3

        First of all,I would like to tell thank you very much for your attention... The problem is very clear I think.. INSERT INTO tbl1 VALUES (........) How can I convert the TextBox string to a SmallDateTime value?

        I 1 Reply Last reply
        0
        • I innocent73

          First of all,I would like to tell thank you very much for your attention... The problem is very clear I think.. INSERT INTO tbl1 VALUES (........) How can I convert the TextBox string to a SmallDateTime value?

          I Offline
          I Offline
          innocent73
          wrote on last edited by
          #4

          string strSQL="INSERT INTO SupplierOperations VALUES (" + txtOrderNum.Text + ",'" + txtModelNum.Text + "','" + ddListVendor.SelectedItem.Text + "','" + DropDownList3.SelectedItem.Text + "','" + txtModelType.Text + "','" + txtModelExp.Text + "','" + ddlistGrup.SelectedItem.Text + "'," + Convert.ToDateTime(Textbox2.Text) + "," + Convert.ToDateTime(TextBox1.Text) + "," +(TextBox6.Text) + "," + txtTerminDayCount.Text + "," + txtOKcount.Text + "," + txtConditionCount.Text + "," + txtStopCount.Text + "," + txtTotalCount.Text + "," + txtControlCount.Text + "," + txtMajor.Text + ")"; try { CollConnection.Open(); SqlCommand cmd=new SqlCommand(strSQL,CollConnection); cmd.ExecuteNonQuery(); . . Enough??

          B 1 Reply Last reply
          0
          • I innocent73

            string strSQL="INSERT INTO SupplierOperations VALUES (" + txtOrderNum.Text + ",'" + txtModelNum.Text + "','" + ddListVendor.SelectedItem.Text + "','" + DropDownList3.SelectedItem.Text + "','" + txtModelType.Text + "','" + txtModelExp.Text + "','" + ddlistGrup.SelectedItem.Text + "'," + Convert.ToDateTime(Textbox2.Text) + "," + Convert.ToDateTime(TextBox1.Text) + "," +(TextBox6.Text) + "," + txtTerminDayCount.Text + "," + txtOKcount.Text + "," + txtConditionCount.Text + "," + txtStopCount.Text + "," + txtTotalCount.Text + "," + txtControlCount.Text + "," + txtMajor.Text + ")"; try { CollConnection.Open(); SqlCommand cmd=new SqlCommand(strSQL,CollConnection); cmd.ExecuteNonQuery(); . . Enough??

            B Offline
            B Offline
            Bhasker Pinninti
            wrote on last edited by
            #5

            hi just try with this. DateTime tempTime = Convert.ToDateTime(DateTime.Now.Tostring()); textbox1.text=tempTime.ToShortDateString(); and call this textbox1 in sql statement Bhasker

            I 1 Reply Last reply
            0
            • B Bhasker Pinninti

              hi just try with this. DateTime tempTime = Convert.ToDateTime(DateTime.Now.Tostring()); textbox1.text=tempTime.ToShortDateString(); and call this textbox1 in sql statement Bhasker

              I Offline
              I Offline
              innocent73
              wrote on last edited by
              #6

              Thank you very much for your attenton...But Unfortunately the result is not correct... I really wonder is this really an IMPOSSIBLE question???

              1 Reply Last reply
              0
              • I innocent73

                Hello Friends, I am really sorry for this stupid question. But I really have to solve this question: I want to execute an INSERT command via my save button on my webform. The procedure like below: ---------------------------------------------------------- string strSQL="INSERT INTO SupplierOperations VALUES (" + txtOrderNum.Text + ",'" + txtModelNum.Text + "','" + TextBox1.Text + "," + . . . . ----------------------------------------------------------- How can I convert TextBox.Text value to SMALLDATETIME I have tried Convert.ToDateTime(TextBox1.Text)....But did not work!! I also copied this code part and tried to run it on to Sql Server Query analyzer and did not work.. Please help...really urgent situation -- modified at 7:45 Thursday 11th May, 2006

                S Offline
                S Offline
                Steve McLenithan
                wrote on last edited by
                #7

                You really need to be using parameters instead of concatenated strings. Not only is it faster, but it's safer. Since you only had 3 fields in your insert statement, that's all I put in this example

                SqlConnection conn = new SqlConnection();
                conn.ConnectionString = "Your_Connection_String_Here";
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = conn;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = @"INSERT INTO [SupplierOperations ] VALUES (@orderNum, @modelNum, @other);"; // <-- paramaters here named whatever you want.

                SqlParameter p1 = new SqlParameter();
                p1.SqlDbType = SqlDbType.NVarChar; // <-- didn't bother guessing the db type for this field or the next one
                p1.ParameterName = "@orderNum";
                p1.Value = txtOrderNum.Text;

                SqlParameter p2 = new SqlParameter();
                p2.SqlDbType = SqlDbType.NVarChar;
                p2.ParameterName = "@modelNum";
                p2.Value = txtModelNum.Text;

                SqlParameter p3 = new SqlParameter();
                p3.SqlDbType = SqlDbType.SmallDateTime; // <-- this is where ado.net automatically converts the value provided to smalldatetime.
                p3.ParameterName = "@other";
                p3.Value = TextBox1.Text;

                cmd.Parameters.AddRange(new SqlParameter[] { p1, p2, p3 });

                cmd.ExecuteNonQuery();

                Found on Bash.org [erno] hm. I've lost a machine.. literally _lost_. it responds to ping, it works completely, I just can't figure out where in my apartment it is.

                -- modified at 13:11 Thursday 11th May, 2006

                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