problem with SQLparameter?
-
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
-
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
r u define @Award_num int output in ur store procedure if no then write it
no knowledge in .net
-
r u define @Award_num int output in ur store procedure if no then write it
no knowledge in .net
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())
-
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())
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
-
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