Hi All,
This is my stored procedure:
and this is my code in vb. net for getting the values
I want to get values from the database and insert into text boxes on page for updation. So I put in the confirmcode in the page and then click on search button and after that the above code runs.
But though the stored procedure works perfectly well in SQL Query Analyzer, I am getting an error
This is my stored procedure:
VB.NET:
[B]CREATE PROCEDURE dbo.UpdateTraveller
(
@ConfirmCode numeric(18,0) ,
@TName nvarchar(50) OUTPUT,
@BDate nvarchar(50) OUTPUT,
@EDate nvarchar(50) OUTPUT,
@EveName nvarchar(50) OUTPUT,
@Desn nvarchar(50) OUTPUT,
@VSize nvarchar (50) OUTPUT
)
as
select @TName =Traveller_Name
from
Travel_Log_db
where
Tvl_Request_id =@ConfirmCode
select @BDate =Travel_begin_date
from Travel_Log_db
where
Tvl_Request_id = @ConfirmCode
select @EDate= travel_end_date
from Travel_Log_db
where
Tvl_Request_id = @ConfirmCode
select @EveName =Event_Name
from Travel_Log_db
where
Tvl_request_id = @ConfirmCode
select @Desn=Destination
from Travel_Log_db
where
Tvl_Request_id = @ConfirmCode
select @VSize=vehicle_size
from Travel_Log_db
where
Tvl_Request_id = @ConfirmCode
GO[/B]
VB.NET:
[B]conn.Open()
Dim command As SqlCommand = New SqlCommand("UpdateTraveller", conn)
command.CommandType = CommandType.StoredProcedure
' ADD VALUES IN STORED PROCEDURE
Dim test As Decimal = CDec(txtConfCode.Text)
command.Parameters.Add("@ConfirmCode", SqlDbType.Decimal).Value = test
command.Parameters.Add("@TName", SqlDbType.NVarChar)
command.Parameters("@TName").Direction = ParameterDirection.Output
command.Parameters.Add("@BDate", SqlDbType.NVarChar)
command.Parameters("@BDate").Direction = ParameterDirection.Output
command.Parameters.Add("@EDate", SqlDbType.NVarChar)
command.Parameters("@EDate").Direction = ParameterDirection.Output
command.Parameters.Add("@EveName", SqlDbType.NVarChar)
command.Parameters("@EveName").Direction = ParameterDirection.Output
command.Parameters.Add("@Desn", SqlDbType.NVarChar)
command.Parameters("@Desn").Direction = ParameterDirection.Output
command.Parameters.Add("@VSize", SqlDbType.NVarChar)
command.Parameters("@VSize").Direction = ParameterDirection.Output
command.ExecuteNonQuery()
Dim tvlName As String = command.Parameters("@TName").Value.ToString()
Dim BgDate As String = command.Parameters("@BDate").Value.ToString()
Dim EnDate As String = command.Parameters("EDate").Value.ToString()
Dim EvName As String = command.Parameters("@EName").Value.ToString()
Dim Destn As String = command.Parameters("@Desn").Value.ToString()
Dim Vehclsize As String = command.Parameters("@VSize").Value.ToString()
txtDestinationUpd.Text = Destn.ToString()
txtVehiclSzUpd.Text = Vehclsize.ToString()
txtTvlNameUpd.Text = tvlName.ToString()
tvtTvlBeginDate.Text = BgDate.ToString()
txtTvlEndDate.Text = EnDate.ToString()
txtTvlEventNameUpd.Text = EvName.ToString()[/B]
But though the stored procedure works perfectly well in SQL Query Analyzer, I am getting an error
Can you please help me out with this?System.InvalidOperationException: String[1]: the Size property has an invalid size of 0. at System.Data.SqlClient.SqlParameter.Validate(Int32 index) at System.Data.SqlClient.SqlCommand.SetUpRPCParameters(_SqlRPC rpc, Int32 startCount, Boolean inSchema, SqlParameterCollection parameters) at System.Data.SqlClient.SqlCommand.BuildRPC(Boolean inSchema, SqlParameterCollection parameters, _SqlRPC& rpc) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) at System.Data.SqlClient.
Last edited by a moderator: