c# - object reference not set to an instance of object sending empty value to sql table -


I get this error

Object is not set to an instance of reference object

When a SQL Server database tries to send an empty value, the column NULL assumes that this is the code of my table

 [Code] [id] [int] identification (1,1) no tap, [numeric] [varchar] (100) tap, [dais] [novework] (10) tap, [lagg] [nervous] (max) tap , [Worker] [int] tap, [inotohor] [nerve] (30) tap, [overtime] [IN T], [urmentia] [nerve] (50) NULL, [viaje] [Navvaker] (50) Faucet, [Almerovers] [decimal] (12, 2) faucet, [PAGE] [decimal] (12, 2) (SqlCOMM = New SqlCommand ("" InsertarDatosReporte ", SqlCON); SqlCOMM.CommandType = System.Data.CommandType.StoredProcedure; SqlCOMM.Parameters.Add ("@ numeroreporte", System.Data.SqlDbType.NVarChar); SqlCOMM.Parameters.Add ("@sp_dias", System.Data.SqlDbType.NVarChar); SqlCOMM.Parameters.Add ("@sp_lugar", System.Data.SqlDbType.NVarChar); SqlCOMM.Parameters.Add ("@ sp_workorder", System.Data.SqlDbType.VarChar); SqlCOMM.Parameters.Add ("@sp_InOutHour", System.Data.SqlDbType.NVarChar); SqlCOMM.Parameters.Add ("@sp_overtime", System.Data.SqlDbType.Int) .ostring (); SqlCOMM.Parameters.Add ("@ sp_emergencia", System.Data.SqlDbType.NVarChar); SqlCOMM.Parameters.Add ("@sp_viaje", System.Data.SqlDbType.NVarChar); SqlCOMM.Parameters.Add ("@sp_almuerzo", System.Data.SqlDbType.Decimal); SqlCOMM.Parameters.Add ("@sp_peaje", System.Data.SqlDbType.Decimal); SqlCOMM.Parameters.Add ("@sp_otros", System.Data.SqlDbType.Decimal); Try {SqlCON.Open (); Foreach (DatagridViewRow line in dgv.Rows) {if (! Row.IsNewRow) {sqlCOMM.Parameters ["@ numeroreporte"] Value = linkLB.Text; SqlCOMM.Parameters ["@ sp_dias"]. Value = line. Seals [0]. Valal.ToString (); SqlCOMM.Parameters ["@ sp_lugar"]. Value = line. Seals [1]. Value Toasting (); SqlCOMM.Parameters ["@ sp_workorder"]. Value = line. Seals [2] value; SqlCOMM.Parameters ["@ sp_InOutHour"]. Value = line. Seals [3]. Valal.ToString (); SqlCOMM.Parameters ["@ sp_overtime"]. Value = line. Cell [4]. value; SqlCOMM.Parameters ["@sp_emergencia"]. Value = row.kel [5]. Value ToString (); SqlCOMM.Parameters ["@ sp_viaje"]. Value = line. Seals [6]. Value ToString (); SqlCOMM.Parameters ["@sp_almuerzo"]. Value = line. Seals [7]. value; SqlCOMM.Parameters ["@sp_peaje"]. Value = line. Cell [8]. value; SqlCOMM.Parameters ["@ sp_otros"]. Value = line. Cell [9]. value; SqlCOMM.ExecuteNonQuery (); }}} Hold (SqlException East) {Message Box.Show (ex.Message); } Hold (Exception pre) {Message Box. Show (ex.Message); } Finally {sqlCON.Close (); The error message that you received shows that a cell where you have the "<">    

Use value.ToString () is actually null . You can not call ToString on the object that does not exist.

There is a solution that you call cell value before and, if it is zero , the parameter value to Assign DBNull.Value A better option would be to bind only the grid to DataTable and then in the blank cell, DBNull.Value will be included in the database by returning you back to the database in DataTable , so there will be no loop.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -