J
JB
Hello
I have a C# program that calls an SQL Server Stored Procedure. First I
pass DateTime.Now to the stored procedure and it returns -1 because all rows
in the table are old therefore it doesn't exist. However 5/3/2009 is an
existing old record in the table but even though I hard code the 5/3/2009 as
a value in the parameter the return value of -1 still is returned it should
not be -1 because this record does exist in the table. I pasted the C# Code
below that passes the parameter to the Stored procedure and beneath it I
pasted the stored procedure:
First is the stored procedure:
*****************************
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Alter PROCEDURE DateExists
@RegDate DateTime
AS
BEGIN
Declare @RetDate int
if not exists(select Date from tblRegistReport where Date = @RegDate)
Begin
set @RetDate = -100
return @RetDate
End
END
GO
Now below is the C# code that passes the date:
**********************************************
namespace recexist
{
public partial class Form1 : Form
{
DateTime RegDate;
//DateTime RetDate;
int RetDate ;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
DataTable tblRegistReport = new DataTable();
//RegDate = DateTime.Now;
RegDate = Convert.ToDateTime("5/3/2009");
RetDate = 0;
SqlConnection connectionString = new SqlConnection("Data
Source=SNYCBOECO0032;Initial
Catalog=VoterRegistration;Uid=sa;pwd=igetalife2");
connectionString.Open();
SqlCommand com = new SqlCommand();
com.Connection = connectionString;
com.CommandText = "DateExists";
com.CommandType = CommandType.StoredProcedure;
com.Parameters.Add("@RegDate", SqlDbType.DateTime);
com.Parameters["@RegDate"].Direction = ParameterDirection.Input;
com.Parameters["@RegDate"].Value = RegDate;
RetDate = com.ExecuteNonQuery();
MessageBox.Show("the number is " + " " + RetDate);
com.Parameters.Clear();
}
}
}
:
I have a C# program that calls an SQL Server Stored Procedure. First I
pass DateTime.Now to the stored procedure and it returns -1 because all rows
in the table are old therefore it doesn't exist. However 5/3/2009 is an
existing old record in the table but even though I hard code the 5/3/2009 as
a value in the parameter the return value of -1 still is returned it should
not be -1 because this record does exist in the table. I pasted the C# Code
below that passes the parameter to the Stored procedure and beneath it I
pasted the stored procedure:
First is the stored procedure:
*****************************
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Alter PROCEDURE DateExists
@RegDate DateTime
AS
BEGIN
Declare @RetDate int
if not exists(select Date from tblRegistReport where Date = @RegDate)
Begin
set @RetDate = -100
return @RetDate
End
END
GO
Now below is the C# code that passes the date:
**********************************************
namespace recexist
{
public partial class Form1 : Form
{
DateTime RegDate;
//DateTime RetDate;
int RetDate ;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
DataTable tblRegistReport = new DataTable();
//RegDate = DateTime.Now;
RegDate = Convert.ToDateTime("5/3/2009");
RetDate = 0;
SqlConnection connectionString = new SqlConnection("Data
Source=SNYCBOECO0032;Initial
Catalog=VoterRegistration;Uid=sa;pwd=igetalife2");
connectionString.Open();
SqlCommand com = new SqlCommand();
com.Connection = connectionString;
com.CommandText = "DateExists";
com.CommandType = CommandType.StoredProcedure;
com.Parameters.Add("@RegDate", SqlDbType.DateTime);
com.Parameters["@RegDate"].Direction = ParameterDirection.Input;
com.Parameters["@RegDate"].Value = RegDate;
RetDate = com.ExecuteNonQuery();
MessageBox.Show("the number is " + " " + RetDate);
com.Parameters.Clear();
}
}
}
: