G
Guest
I have created a class and stored procedure to insert records into a table.
The insert works but only the first character of the "Title" and "Body"
fields are added. I have traced up to the point of executing the sproc and
the string values are intact up to this point. Below is my code for the
SPROC and the insert method of the class:
.........................................................................................
Sproc
.........................................................................................
CREATE PROCEDURE spAddBlog
@pTitle varchar,
@pBody varchar,
@pStartdate datetime,
@pEnddate datetime,
@pActive bit
AS
INSERT INTO blog
Values (@pTitle,@pBody,@pStartdate,@pEnddate,@pActive)
GO
.........................................................................................
Class
.........................................................................................
mStartdate = DateTime.Now;
mEnddate = DateTime.Now;
mActive = 1;
/* Connection Object */
SqlConnection conn = new
SqlConnection(ConfigurationSettings.AppSetting["connString"]);
conn.Open();
/* Command Object */
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandText = "spAddBlog";
comm.CommandType = CommandType.StoredProcedure;
SqlParameter objParam;
objParam = comm.Parameters.Add("@pTitle",SqlDbType.VarChar);
objParam.Direction = ParameterDirection.Input;
objParam.Value = mTitle;
objParam = comm.Parameters.Add("@pBody",SqlDbType.VarChar);
objParam.Direction = ParameterDirection.Input;
objParam.Value = mBody;
objParam = comm.Parameters.Add("@pStartdate",SqlDbType.DateTime);
objParam.Direction = ParameterDirection.Input;
objParam.Value = mStartdate;
objParam = comm.Parameters.Add("@pEnddate",SqlDbType.DateTime);
objParam.Direction = ParameterDirection.Input;
objParam.Value = mEnddate;
objParam = comm.Parameters.Add("@pActive",SqlDbType.Bit);
objParam.Direction = ParameterDirection.Input;
objParam.Value = mActive;
try
{
comm.ExecuteNonQuery();
comm.Dispose();
return true;
}
catch
{
return false;
}
The insert works but only the first character of the "Title" and "Body"
fields are added. I have traced up to the point of executing the sproc and
the string values are intact up to this point. Below is my code for the
SPROC and the insert method of the class:
.........................................................................................
Sproc
.........................................................................................
CREATE PROCEDURE spAddBlog
@pTitle varchar,
@pBody varchar,
@pStartdate datetime,
@pEnddate datetime,
@pActive bit
AS
INSERT INTO blog
Values (@pTitle,@pBody,@pStartdate,@pEnddate,@pActive)
GO
.........................................................................................
Class
.........................................................................................
mStartdate = DateTime.Now;
mEnddate = DateTime.Now;
mActive = 1;
/* Connection Object */
SqlConnection conn = new
SqlConnection(ConfigurationSettings.AppSetting["connString"]);
conn.Open();
/* Command Object */
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandText = "spAddBlog";
comm.CommandType = CommandType.StoredProcedure;
SqlParameter objParam;
objParam = comm.Parameters.Add("@pTitle",SqlDbType.VarChar);
objParam.Direction = ParameterDirection.Input;
objParam.Value = mTitle;
objParam = comm.Parameters.Add("@pBody",SqlDbType.VarChar);
objParam.Direction = ParameterDirection.Input;
objParam.Value = mBody;
objParam = comm.Parameters.Add("@pStartdate",SqlDbType.DateTime);
objParam.Direction = ParameterDirection.Input;
objParam.Value = mStartdate;
objParam = comm.Parameters.Add("@pEnddate",SqlDbType.DateTime);
objParam.Direction = ParameterDirection.Input;
objParam.Value = mEnddate;
objParam = comm.Parameters.Add("@pActive",SqlDbType.Bit);
objParam.Direction = ParameterDirection.Input;
objParam.Value = mActive;
try
{
comm.ExecuteNonQuery();
comm.Dispose();
return true;
}
catch
{
return false;
}