3
Answers

unable to insert data. Pls help.

wooi83

wooi83

21y
2.2k
1
i need to know why i can't insert both variables to my database? it keeps return false when i click save button. no compilation and runtime errors occur. is my database table restricted access or my sql query is has erros? please give suggestion for this. public bool StoreBooksReservation(string UID, string BID) { SqlParameter[] Param = { new SqlParameter("@reservationUserID", SqlDbType.VarChar), new SqlParameter("@reservationBookID", SqlDbType.VarChar) }; Param[0].Value = UID; Param[1].Value = BID; try { return DC.SProcedures("SP_InsertReserve", Param); } catch { return false; } } public bool SProcedures(String SProcName, SqlParameter[] Param) { SqlCommand myCmd = CreateCommand(SProcName, Param, CommandType.StoredProcedure); try { myCmd.ExecuteNonQuery(); return true; } catch { return false; } } //stored procedure in sql 2000 CREATE PROCEDURE SP_InsertReserve ( @reservationUserID varchar, @reservationBookID varchar ) AS INSERT INTO dbo.RESERVATIONS( dbo.RESERVATIONS.reservationUserID, dbo.RESERVATIONS.reservationBookID ) VALUES ( @reservationUserID,@reservationBookID ) GO
Answers (3)
0
wooi83
NA 18 0 21y
thanks for mentioning connection string. i did close the connection in the connection method. infact i mustn't do that.. thanks alot...
0
subbaram_k
NA 2 0 21y
int intParamCount = 0; SqlParameter[] sqlParam=new SqlParameter[2]; SqlCommand objInsertCommand=new SqlCommand("sp_InsertReserve",objConn); //specify the connection objInsertCommand.CommandType =CommandType.StoredProcedure; //Associate Parameters sqlParam[0]=new SqlParameter("@reservationUserID",SqlDbType.VarChar ); sqlParam[0].Direction =ParameterDirection.Input ; sqlParam[0].Value =UID; sqlParam[1]=new SqlParameter("@reservationBookID",SqlDbType.VarChar ); sqlParam[1].Direction =ParameterDirection.Input ; sqlParam[1].Value =BID; while(intParamCount
0
jaac79
NA 34 0 21y
In your code where are you setting the connection object?
Next Recommended Forum