Quantcast
Viewing all articles
Browse latest Browse all 27020

SQL parameter SqlDBtype is INt, value being passed to stored procedure must be null

I am just getting my feet wet with VB (fourth week). Using VS 2010, SQL Server 2008 R2

Am trying to read a table which has stored values of NULL for columns designed as Int. Am reading via a stored procedure. Am not getting any returned values.



I have a table designed as follows:
I know the table has the record (CompanyCode_int, AcctYear_int, GlAccount1_int, GlAccount2_int, GlAccount3_int) the GlAccount2_int and GlAccount3_int values in the table are NULL, which is what I believe is creating my problem.

CREATE TABLE [dbo].[GlChartAccounts](
[CompanyCode_int] [int] NULL,
[AcctYear_int] [int] NULL,
[GlAccount1_int] [int] NULL,
[GlAccount2_int] [int] NULL,
[GlAccount3_int] [int] NULL,
[AccountDescription] [varchar](40) NULL,
[DebitCreditCode] [varchar](1) NULL,
[AssetLiabilityCode] [varchar](1) NULL,
[BalanceSheetControl_int] [int] NULL,
[IncomeSheetControl_int] [int] NULL,
[CombinedSheetControl_int] [int] NULL,

My stored procedure to access the table is:
@Action int = null,
@Exists int = null output,
@CompanyCode_int int = null,
@AcctYear_int int = null,
@GlAccount1_int int = null output,
@GlAccount2_int int = null output,
@GlAccount3_int int = null output,
@AccountDescription varchar(40) = null output

As
Begin

--********************************************************************
--*
--********************************************************************
If @Action = 1
Begin
If Exists (Select * From GlChartAccounts
Where
GlChartAccounts.CompanyCode_int = @CompanyCode_int And
GlChartAccounts.AcctYear_int = @AcctYear_int And
GlChartAccounts.GlAccount1_int = @GlAccount1_int And
GlChartAccounts.GlAccount2_int = @GlAccount2_int And
GlChartAccounts.GlAccount3_int = @GlAccount3_int)
Begin
Select
@Glaccount1_int = GlChartAccounts.GlAccount1_int,
@GlAccount2_int = GlChartAccounts.GlAccount2_int,
@GlAccount3_int = GlChartAccounts.GlAccount3_int,
@AccountDescription = GlChartAccounts.AccountDescription,
From GlChartAccounts
Where
GlChartAccounts.CompanyCode_int = @CompanyCode_int And
GlChartAccounts.AcctYear_int = @AcctYear_int And
GlhartAccounts.GlAccount1_int = @GlAccount1_int And
GlChartAccounts.GlAccount2_int = @GlAccount2_int And
GlChartAccounts.GlAccount3_int = @GlAccount3_int
Begin
Set @Exists = 1
End
End
Else
Begin
Set @Exists = 0
End
End



The section of VB code attempting to read the table:
Using cmd As New SqlClient.SqlCommand("spGetTableGlChartAccounts", GetOpenConnection) With {.CommandType = CommandType.StoredProcedure}
With cmd.Parameters
.Add(New SqlParameter("@Action", SqlDbType.Int)).Value = 1
.Add(New SqlParameter("@Exists", SqlDbType.Int)).Direction = ParameterDirection.InputOutput
.Add(New SqlParameter("@CompanyCode_int", SqlDbType.Int)).Value = prmCompanyCode_int
.Add(New SqlParameter("@AcctYear_int", SqlDbType.Int)).Value = CInt(prmAcctYear_int)
If prmGlaccount1_int <> "" Then
.Add(New SqlParameter("@GlAccount1_int", SqlDbType.Int)).Value = CInt(prmGlaccount1_int)
End If
If prmGlaccount2_int <> "" Then
.Add(New SqlParameter("@GlAccount2_int", SqlDbType.Int)).Value = CInt(prmGlaccount2_int)
Else
.Add(New SqlParameter("@GlAccount2_int", SqlDbType.Int)).Value = DBNull.Value
End If
If prmGlaccount3_int <> "" Then
.Add(New SqlParameter("@GlAccount3_int", SqlDbType.Int)).Value = CInt(prmGlaccount3_int)
Else
.Add(New SqlParameter("@GlAccount3_int", SqlDbType.Int)).Value = DBNull.Value
End If
.Add(New SqlParameter("@AccountDescription", SqlDbType.VarChar, -1)).Direction = ParameterDirection.InputOutput
End With

Viewing all articles
Browse latest Browse all 27020

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>