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.DateTi me);
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;
} 1 1271
you have to specify the size of varchar... if you dont specify its taken as
just a char
CREATE PROCEDURE spAddBlog
@pTitle varchar(100),
@pBody varchar(3000),
.......
also
objParam = comm.Parameters.Add("@pTitle",SqlDbType.VarChar, 100);
objParam.Direction = ParameterDirection.Input;
objParam.Value = mTitle;
objParam = comm.Parameters.Add("@pBody",SqlDbType.VarChar,300 0);
objParam.Direction = ParameterDirection.Input;
objParam.Value = mBody;
--
Regards,
Hermit Dave
( http://hdave.blogspot.com)
"NathanV" <Na*****@discussions.microsoft.com> wrote in message
news:86**********************************@microsof t.com... 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.DateTi me); 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; } This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: DTB |
last post by:
I am having trouble creating an INSTEAD OF trigger in SQL Server to
replicate a BEFORE UPDATE trigger from ORACLE.
Here is a sample of the ORACLE BEFORE UPDATE trigger:
CREATE TRIGGER myTRIGGER ON...
|
by: jet |
last post by:
Hi,
Maybe this is an easy task, but I'm having a really hard time figuring
out how to do this. I'm a complete newbie to SQL Server.
I have a database dump file from MySQL that's in .sql...
|
by: HB Kim |
last post by:
Hello,
What could possibly cause data in the SQL server database to be
removed, except being deleted manually? We had a couple of situations
where data in certain records disappeared although the...
|
by: iqbal |
last post by:
Hi all,
We have an application through which we are bulk inserting rows into a
view. The definition of the view is such that it selects columns from
a table on a remote server. I have added the...
|
by: Robin Lawrie |
last post by:
Hi again, another problem!
I've moved from an Access database to SQL server and am now having trouble
inserting dates and times into seperate fields. I'm using ASP and the code
below to get the...
|
by: Ritesh |
last post by:
Hi All,
According to my observation using SP_WHO2 in my database, some INSERT
statements are getting blocked by SELECT statements. Though the
blocking
SELECT statement is having ReadPast hint,...
|
by: Steve Kuekes |
last post by:
I have two sql servers, I have defined each one as a linked server to
the other. I can mostly access the servers from one another, but I get
the following error on a sql insert.
Insert...
|
by: Charles Wilt |
last post by:
I have a IBM iSeries (aka AS-400) running v5r3 of OS/400 that I access
via a linked server from SQL Server 2000.
The following select works fine:
select * from...
|
by: Tonio Tanzi |
last post by:
I have the following problem in a Win 2000 Server + SQL Server 2000
environment and I hope somewhat can help me to resolve it (after many
days of useless attempts I am desperate).
In my database...
|
by: Andres Rormoser |
last post by:
I'm having a performance Issue with my Production SQL Server (2 x Xeon
Dual-Core Woodcrest 1.6Ghz, 2GB RAM, IIS, SQL Server). In general the
querys take much longer than the querys in my...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |