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. null reference exception not set to create an object instance

null reference exception not set to create an object instance

Scheduled Pinned Locked Moved C#
databasedesignsecurityhelptutorial
7 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.
  • J Offline
    J Offline
    joynee
    wrote on last edited by
    #1

    i have a number in my table that i need to inser in the database.the loop is returning a null value.how to convert object to string .here is my code. can anyone help on this.. using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.OracleClient; /// <summary> /// Summary description for TMPerminent /// </summary> public class TMPerminent { #region Variables OracleConnection con; #endregion #region CONNECTION STRING public string connectionString = System.Configuration.ConfigurationManager.AppSettings["OracleConnectionString2"]; # endregion public TMPerminent() { OracleConnection con = new OracleConnection(connectionString); } //public void AddNewRow(DataRow gvWeekDays,DataRow gvHrsNewRow, DataRow gvTaskNewRow, string strTWODID,string strEmpTSID) public void AddNewRow(string dayid, string dayhrs, ref DataRow gvTaskNewRow, string strTWODID, string strEmpTSID) { //string strDay = null; //string strHrs = null; //Get the values stored in the text boxes string txtDivision = gvTaskNewRow[0].ToString(); string txtSegment = gvTaskNewRow[1].ToString(); string txtDetail = "0";//gvTaskNewRow[2].ToString(); string txtFuntion = "0";//gvTaskNewRow[3].ToString(); string txtDescription = "0";//gvTaskNewRow[4].ToString(); string txtTask = "0";//gvTaskNewRow[5].ToString(); string txtCounty = "0";//gvTaskNewRow[6].ToString(); string txtHighway = "0";//gvTaskNewRow[7].ToString(); //Get the values stored in the text boxes txtDivision = gvTaskNewRow[0].ToString(); txtSegment = gvTaskNewRow[1].ToString(); txtDetail = gvTaskNewRow[2].ToString(); txtFuntion = gvTaskNewRow[3].ToString(); txtDescription = gvTaskNewRow[4].ToString(); txtTask = gvTaskNewRow[5].ToString(); txtCounty = gvTaskNewRow[6].ToString(); txtHighway = gvTaskNewRow[7].ToString(); //Prepare the insert Command of the DataSource control (inserting new record into the TASK TABLE) string strInsertTask = ""; strInsertTask = "insert into TASK_WRK_ORDR_DTL (TXDOT_DIST_NBR,SGMNT_ID,DTL_CD,FUNC_CD,TASK_WRK_ORDR_CD,TXDOT_CNTY_NBR,HWY_CD,MISC_DSCR_TXT) valu

    L G R 3 Replies Last reply
    0
    • J joynee

      i have a number in my table that i need to inser in the database.the loop is returning a null value.how to convert object to string .here is my code. can anyone help on this.. using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.OracleClient; /// <summary> /// Summary description for TMPerminent /// </summary> public class TMPerminent { #region Variables OracleConnection con; #endregion #region CONNECTION STRING public string connectionString = System.Configuration.ConfigurationManager.AppSettings["OracleConnectionString2"]; # endregion public TMPerminent() { OracleConnection con = new OracleConnection(connectionString); } //public void AddNewRow(DataRow gvWeekDays,DataRow gvHrsNewRow, DataRow gvTaskNewRow, string strTWODID,string strEmpTSID) public void AddNewRow(string dayid, string dayhrs, ref DataRow gvTaskNewRow, string strTWODID, string strEmpTSID) { //string strDay = null; //string strHrs = null; //Get the values stored in the text boxes string txtDivision = gvTaskNewRow[0].ToString(); string txtSegment = gvTaskNewRow[1].ToString(); string txtDetail = "0";//gvTaskNewRow[2].ToString(); string txtFuntion = "0";//gvTaskNewRow[3].ToString(); string txtDescription = "0";//gvTaskNewRow[4].ToString(); string txtTask = "0";//gvTaskNewRow[5].ToString(); string txtCounty = "0";//gvTaskNewRow[6].ToString(); string txtHighway = "0";//gvTaskNewRow[7].ToString(); //Get the values stored in the text boxes txtDivision = gvTaskNewRow[0].ToString(); txtSegment = gvTaskNewRow[1].ToString(); txtDetail = gvTaskNewRow[2].ToString(); txtFuntion = gvTaskNewRow[3].ToString(); txtDescription = gvTaskNewRow[4].ToString(); txtTask = gvTaskNewRow[5].ToString(); txtCounty = gvTaskNewRow[6].ToString(); txtHighway = gvTaskNewRow[7].ToString(); //Prepare the insert Command of the DataSource control (inserting new record into the TASK TABLE) string strInsertTask = ""; strInsertTask = "insert into TASK_WRK_ORDR_DTL (TXDOT_DIST_NBR,SGMNT_ID,DTL_CD,FUNC_CD,TASK_WRK_ORDR_CD,TXDOT_CNTY_NBR,HWY_CD,MISC_DSCR_TXT) valu

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      joynee wrote:

      strInsertTask = "insert into TASK_WRK_ORDR_DTL (TXDOT_DIST_NBR,SGMNT_ID,DTL_CD,FUNC_CD,TASK_WRK_ORDR_CD,TXDOT_CNTY_NBR,HWY_CD,MISC_DSCR_TXT) values (" + txtDivision + "," + txtSegment + "," + txtDetail + "," + txtFuntion + "," + txtTask + "," + txtCounty + "," + txtHighway + "," + txtDescription + ")";

      Ah yes, string concatenation. Could someone please tell me what year it is? I'm sure I must have the wrong calendar. Dear joynee, you might want to do some research on something called "SQL injection".

      J 1 Reply Last reply
      0
      • L led mike

        joynee wrote:

        strInsertTask = "insert into TASK_WRK_ORDR_DTL (TXDOT_DIST_NBR,SGMNT_ID,DTL_CD,FUNC_CD,TASK_WRK_ORDR_CD,TXDOT_CNTY_NBR,HWY_CD,MISC_DSCR_TXT) values (" + txtDivision + "," + txtSegment + "," + txtDetail + "," + txtFuntion + "," + txtTask + "," + txtCounty + "," + txtHighway + "," + txtDescription + ")";

        Ah yes, string concatenation. Could someone please tell me what year it is? I'm sure I must have the wrong calendar. Dear joynee, you might want to do some research on something called "SQL injection".

        J Offline
        J Offline
        joynee
        wrote on last edited by
        #3

        [Message Deleted]

        L 1 Reply Last reply
        0
        • J joynee

          [Message Deleted]

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          Well in 2008 if someone suggests you research something the obvious thing to do is type it into the Google keyword search input and click the search button. Then you attempt to locate a result that seems to provide a description of the item and read it. However I can see how that might seem counter intuitive to posting a question in a forum, wait, no actually I can't.

          1 Reply Last reply
          0
          • J joynee

            i have a number in my table that i need to inser in the database.the loop is returning a null value.how to convert object to string .here is my code. can anyone help on this.. using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.OracleClient; /// <summary> /// Summary description for TMPerminent /// </summary> public class TMPerminent { #region Variables OracleConnection con; #endregion #region CONNECTION STRING public string connectionString = System.Configuration.ConfigurationManager.AppSettings["OracleConnectionString2"]; # endregion public TMPerminent() { OracleConnection con = new OracleConnection(connectionString); } //public void AddNewRow(DataRow gvWeekDays,DataRow gvHrsNewRow, DataRow gvTaskNewRow, string strTWODID,string strEmpTSID) public void AddNewRow(string dayid, string dayhrs, ref DataRow gvTaskNewRow, string strTWODID, string strEmpTSID) { //string strDay = null; //string strHrs = null; //Get the values stored in the text boxes string txtDivision = gvTaskNewRow[0].ToString(); string txtSegment = gvTaskNewRow[1].ToString(); string txtDetail = "0";//gvTaskNewRow[2].ToString(); string txtFuntion = "0";//gvTaskNewRow[3].ToString(); string txtDescription = "0";//gvTaskNewRow[4].ToString(); string txtTask = "0";//gvTaskNewRow[5].ToString(); string txtCounty = "0";//gvTaskNewRow[6].ToString(); string txtHighway = "0";//gvTaskNewRow[7].ToString(); //Get the values stored in the text boxes txtDivision = gvTaskNewRow[0].ToString(); txtSegment = gvTaskNewRow[1].ToString(); txtDetail = gvTaskNewRow[2].ToString(); txtFuntion = gvTaskNewRow[3].ToString(); txtDescription = gvTaskNewRow[4].ToString(); txtTask = gvTaskNewRow[5].ToString(); txtCounty = gvTaskNewRow[6].ToString(); txtHighway = gvTaskNewRow[7].ToString(); //Prepare the insert Command of the DataSource control (inserting new record into the TASK TABLE) string strInsertTask = ""; strInsertTask = "insert into TASK_WRK_ORDR_DTL (TXDOT_DIST_NBR,SGMNT_ID,DTL_CD,FUNC_CD,TASK_WRK_ORDR_CD,TXDOT_CNTY_NBR,HWY_CD,MISC_DSCR_TXT) valu

            G Offline
            G Offline
            Giorgi Dalakishvili
            wrote on last edited by
            #5

            Ever heard about SQL Injection Attacks and Some Tips on How to Prevent Them[^] ? I guess no

            Giorgi Dalakishvili #region signature my articles #endregion

            1 Reply Last reply
            0
            • J joynee

              i have a number in my table that i need to inser in the database.the loop is returning a null value.how to convert object to string .here is my code. can anyone help on this.. using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.OracleClient; /// <summary> /// Summary description for TMPerminent /// </summary> public class TMPerminent { #region Variables OracleConnection con; #endregion #region CONNECTION STRING public string connectionString = System.Configuration.ConfigurationManager.AppSettings["OracleConnectionString2"]; # endregion public TMPerminent() { OracleConnection con = new OracleConnection(connectionString); } //public void AddNewRow(DataRow gvWeekDays,DataRow gvHrsNewRow, DataRow gvTaskNewRow, string strTWODID,string strEmpTSID) public void AddNewRow(string dayid, string dayhrs, ref DataRow gvTaskNewRow, string strTWODID, string strEmpTSID) { //string strDay = null; //string strHrs = null; //Get the values stored in the text boxes string txtDivision = gvTaskNewRow[0].ToString(); string txtSegment = gvTaskNewRow[1].ToString(); string txtDetail = "0";//gvTaskNewRow[2].ToString(); string txtFuntion = "0";//gvTaskNewRow[3].ToString(); string txtDescription = "0";//gvTaskNewRow[4].ToString(); string txtTask = "0";//gvTaskNewRow[5].ToString(); string txtCounty = "0";//gvTaskNewRow[6].ToString(); string txtHighway = "0";//gvTaskNewRow[7].ToString(); //Get the values stored in the text boxes txtDivision = gvTaskNewRow[0].ToString(); txtSegment = gvTaskNewRow[1].ToString(); txtDetail = gvTaskNewRow[2].ToString(); txtFuntion = gvTaskNewRow[3].ToString(); txtDescription = gvTaskNewRow[4].ToString(); txtTask = gvTaskNewRow[5].ToString(); txtCounty = gvTaskNewRow[6].ToString(); txtHighway = gvTaskNewRow[7].ToString(); //Prepare the insert Command of the DataSource control (inserting new record into the TASK TABLE) string strInsertTask = ""; strInsertTask = "insert into TASK_WRK_ORDR_DTL (TXDOT_DIST_NBR,SGMNT_ID,DTL_CD,FUNC_CD,TASK_WRK_ORDR_CD,TXDOT_CNTY_NBR,HWY_CD,MISC_DSCR_TXT) valu

              R Offline
              R Offline
              Ravenet
              wrote on last edited by
              #6

              Hi i found in your code , this code snippet //Get the values stored in the text boxes txtDivision = gvTaskNewRow[0].ToString(); txtSegment = gvTaskNewRow[1].ToString(); txtDetail = gvTaskNewRow[2].ToString(); txtFuntion = gvTaskNewRow[3].ToString(); txtDescription = gvTaskNewRow[4].ToString(); txtTask = gvTaskNewRow[5].ToString(); txtCounty = gvTaskNewRow[6].ToString(); txtHighway = gvTaskNewRow[7].ToString(); please check is it correct? i think that should be like this //Get the values stored in the text boxes txtDivision.Text = gvTaskNewRow[0].ToString(); --- thanks

              Cheers,Earn and Enjoy RRave MCTS,MCPD http://ravesoft.blogspot.com

              J 1 Reply Last reply
              0
              • R Ravenet

                Hi i found in your code , this code snippet //Get the values stored in the text boxes txtDivision = gvTaskNewRow[0].ToString(); txtSegment = gvTaskNewRow[1].ToString(); txtDetail = gvTaskNewRow[2].ToString(); txtFuntion = gvTaskNewRow[3].ToString(); txtDescription = gvTaskNewRow[4].ToString(); txtTask = gvTaskNewRow[5].ToString(); txtCounty = gvTaskNewRow[6].ToString(); txtHighway = gvTaskNewRow[7].ToString(); please check is it correct? i think that should be like this //Get the values stored in the text boxes txtDivision.Text = gvTaskNewRow[0].ToString(); --- thanks

                Cheers,Earn and Enjoy RRave MCTS,MCPD http://ravesoft.blogspot.com

                J Offline
                J Offline
                Justin Perez
                wrote on last edited by
                #7

                No, his code is correct. You don't need to set the .Text property on a string. He prefixed the variables like it was a text box, but they were actually strings.

                I'm going to become rich when I create a device that allows me to punch people in the face over the internet. "If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer

                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