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. Database & SysAdmin
  3. Database
  4. problem with SQLparameter?

problem with SQLparameter?

Scheduled Pinned Locked Moved Database
questiondatabasehelp
5 Posts 3 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.
  • M Offline
    M Offline
    Mr Kode
    wrote on last edited by
    #1

    i have the following code: SqlCommand insertcommand = new SqlCommand(); insertcommand.Connection = con; //connection to SQLserver2000 insertcommand.CommandType = CommandType.StoredProcedure; insertcommand.CommandText = "InsertQueryoperation"; SqlParameter AwardNum = new SqlParameter("@Award_num",SqlDbType.Int); //@Award_num SQL Variable on InsertQueryoperation procedure AwardNum.Direction = ParameterDirection.Output; // parameter should sent the data to DataSource txtAward.Text=AwardNum.Value.ToString(); insertcommand.Parameters.Add(AwardNum); insertcommand.Connection.Open(); insertcommand.ExecuteNonQuery(); //NullReferenceException Accoured here insertcommand.Connection.Close(); what is the problem with that code? regards

    U L 2 Replies Last reply
    0
    • M Mr Kode

      i have the following code: SqlCommand insertcommand = new SqlCommand(); insertcommand.Connection = con; //connection to SQLserver2000 insertcommand.CommandType = CommandType.StoredProcedure; insertcommand.CommandText = "InsertQueryoperation"; SqlParameter AwardNum = new SqlParameter("@Award_num",SqlDbType.Int); //@Award_num SQL Variable on InsertQueryoperation procedure AwardNum.Direction = ParameterDirection.Output; // parameter should sent the data to DataSource txtAward.Text=AwardNum.Value.ToString(); insertcommand.Parameters.Add(AwardNum); insertcommand.Connection.Open(); insertcommand.ExecuteNonQuery(); //NullReferenceException Accoured here insertcommand.Connection.Close(); what is the problem with that code? regards

      U Offline
      U Offline
      Unknown Ajanabi
      wrote on last edited by
      #2

      r u define @Award_num int output in ur store procedure if no then write it

      no knowledge in .net

      M 1 Reply Last reply
      0
      • U Unknown Ajanabi

        r u define @Award_num int output in ur store procedure if no then write it

        no knowledge in .net

        M Offline
        M Offline
        Mr Kode
        wrote on last edited by
        #3

        yes i did, here is the stored procedure: i create it by command builder CREATE PROCEDURE dbo.InsertQueryoperation ( @Award_num int, @patient_name varchar(40), @Operation_date smalldatetime, @Duration smalldatetime, @Surgean_name varchar(40), @Type_of_operation varchar(20), @Anaesthiologist_name varchar(40), @Type_of_anaesthesia varchar(20), @ID_num int ) AS SET NOCOUNT OFF INSERT INTO Operation_details (Award_num, patient_name, Operation_date, Duration, Surgean_name, Type_of_operation, Anaesthiologist_name, Type_of_anaesthesia, ID_num) VALUES (@Award_num,@patient_name,@Operation_date,@Duration,@Surgean_name,@Type_of_operation,@Anaesthiologist_name,@Type_of_anaesthesia,@ID_num); SELECT Operation_ID, Award_num, patient_name, Operation_date, Duration, Surgean_name, Type_of_operation, Anaesthiologist_name, Type_of_anaesthesia, surgean_ID, Anaesthiologist_ID, ID_num FROM Operation_details WHERE (Operation_ID = SCOPE_IDENTITY())

        U 1 Reply Last reply
        0
        • M Mr Kode

          yes i did, here is the stored procedure: i create it by command builder CREATE PROCEDURE dbo.InsertQueryoperation ( @Award_num int, @patient_name varchar(40), @Operation_date smalldatetime, @Duration smalldatetime, @Surgean_name varchar(40), @Type_of_operation varchar(20), @Anaesthiologist_name varchar(40), @Type_of_anaesthesia varchar(20), @ID_num int ) AS SET NOCOUNT OFF INSERT INTO Operation_details (Award_num, patient_name, Operation_date, Duration, Surgean_name, Type_of_operation, Anaesthiologist_name, Type_of_anaesthesia, ID_num) VALUES (@Award_num,@patient_name,@Operation_date,@Duration,@Surgean_name,@Type_of_operation,@Anaesthiologist_name,@Type_of_anaesthesia,@ID_num); SELECT Operation_ID, Award_num, patient_name, Operation_date, Duration, Surgean_name, Type_of_operation, Anaesthiologist_name, Type_of_anaesthesia, surgean_ID, Anaesthiologist_ID, ID_num FROM Operation_details WHERE (Operation_ID = SCOPE_IDENTITY())

          U Offline
          U Offline
          Unknown Ajanabi
          wrote on last edited by
          #4

          CREATE PROCEDURE dbo.InsertQueryoperation ( @Award_num int output, @patient_name varchar(40), @Operation_date smalldatetime, @Duration smalldatetime, @Surgean_name varchar(40), @Type_of_operation varchar(20), @Anaesthiologist_name varchar(40), @Type_of_anaesthesia varchar(20), @ID_num int ) AS SET NOCOUNT OFF INSERT INTO Operation_details (Award_num, patient_name, Operation_date, Duration, Surgean_name, Type_of_operation, Anaesthiologist_name, Type_of_anaesthesia, ID_num) VALUES (@Award_num,@patient_name,@Operation_date,@Duration,@Surgean_name,@Type_of_operation,@Anaesthiologist_name,@Type_of_anaesthesia,@ID_num); SELECT Operation_ID, Award_num, patient_name, Operation_date, Duration, Surgean_name, Type_of_operation, Anaesthiologist_name, Type_of_anaesthesia, surgean_ID, Anaesthiologist_ID, ID_num FROM Operation_details WHERE (Operation_ID = SCOPE_IDENTITY()) i hv change ur parameter @award_num int output pest this code to ur store procedure. try this

          no knowledge in .net

          1 Reply Last reply
          0
          • M Mr Kode

            i have the following code: SqlCommand insertcommand = new SqlCommand(); insertcommand.Connection = con; //connection to SQLserver2000 insertcommand.CommandType = CommandType.StoredProcedure; insertcommand.CommandText = "InsertQueryoperation"; SqlParameter AwardNum = new SqlParameter("@Award_num",SqlDbType.Int); //@Award_num SQL Variable on InsertQueryoperation procedure AwardNum.Direction = ParameterDirection.Output; // parameter should sent the data to DataSource txtAward.Text=AwardNum.Value.ToString(); insertcommand.Parameters.Add(AwardNum); insertcommand.Connection.Open(); insertcommand.ExecuteNonQuery(); //NullReferenceException Accoured here insertcommand.Connection.Close(); what is the problem with that code? regards

            L Offline
            L Offline
            leckey 0
            wrote on last edited by
            #5

            Repost

            Shhhhh..... http://craptasticnation.blogspot.com/[^]

            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