473,790 Members | 2,421 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Server Insert Problem

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,@p Enddate,@pActiv e)
GO
............... ............... ............... ............... ............... ..............
Class
............... ............... ............... ............... ............... ..............
mStartdate = DateTime.Now;
mEnddate = DateTime.Now;
mActive = 1;

/* Connection Object */
SqlConnection conn = new
SqlConnection(C onfigurationSet tings.AppSettin g["connString "]);
conn.Open();

/* Command Object */
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandTex t = "spAddBlog" ;
comm.CommandTyp e = CommandType.Sto redProcedure;

SqlParameter objParam;

objParam = comm.Parameters .Add("@pTitle", SqlDbType.VarCh ar);
objParam.Direct ion = ParameterDirect ion.Input;
objParam.Value = mTitle;

objParam = comm.Parameters .Add("@pBody",S qlDbType.VarCha r);
objParam.Direct ion = ParameterDirect ion.Input;
objParam.Value = mBody;

objParam = comm.Parameters .Add("@pStartda te",SqlDbType.D ateTime);
objParam.Direct ion = ParameterDirect ion.Input;
objParam.Value = mStartdate;

objParam = comm.Parameters .Add("@pEnddate ",SqlDbType.Dat eTime);
objParam.Direct ion = ParameterDirect ion.Input;
objParam.Value = mEnddate;

objParam = comm.Parameters .Add("@pActive" ,SqlDbType.Bit) ;
objParam.Direct ion = ParameterDirect ion.Input;
objParam.Value = mActive;

try
{
comm.ExecuteNon Query();
comm.Dispose();
return true;
}
catch
{
return false;
}

Nov 18 '05 #1
1 1281
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.VarCh ar, 100);
objParam.Direct ion = ParameterDirect ion.Input;
objParam.Value = mTitle;

objParam = comm.Parameters .Add("@pBody",S qlDbType.VarCha r,3000);
objParam.Direct ion = ParameterDirect ion.Input;
objParam.Value = mBody;
--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"NathanV" <Na*****@discus sions.microsoft .com> wrote in message
news:86******** *************** ***********@mic rosoft.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,@p Enddate,@pActiv e)
GO
............... ............... ............... ............... ............... ..
............. Class:
............... ............... ............... ............... ............... ..
............. mStartdate = DateTime.Now;
mEnddate = DateTime.Now;
mActive = 1;

/* Connection Object */
SqlConnection conn = new
SqlConnection(C onfigurationSet tings.AppSettin g["connString "]);
conn.Open();

/* Command Object */
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandTex t = "spAddBlog" ;
comm.CommandTyp e = CommandType.Sto redProcedure;

SqlParameter objParam;

objParam = comm.Parameters .Add("@pTitle", SqlDbType.VarCh ar);
objParam.Direct ion = ParameterDirect ion.Input;
objParam.Value = mTitle;

objParam = comm.Parameters .Add("@pBody",S qlDbType.VarCha r);
objParam.Direct ion = ParameterDirect ion.Input;
objParam.Value = mBody;

objParam = comm.Parameters .Add("@pStartda te",SqlDbType.D ateTime);
objParam.Direct ion = ParameterDirect ion.Input;
objParam.Value = mStartdate;

objParam = comm.Parameters .Add("@pEnddate ",SqlDbType.Dat eTime);
objParam.Direct ion = ParameterDirect ion.Input;
objParam.Value = mEnddate;

objParam = comm.Parameters .Add("@pActive" ,SqlDbType.Bit) ;
objParam.Direct ion = ParameterDirect ion.Input;
objParam.Value = mActive;

try
{
comm.ExecuteNon Query();
comm.Dispose();
return true;
}
catch
{
return false;
}

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
22200
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 MYTABLE begin :new.DT := SYSDATE; if :new.NM is NULL then :new.NM := USER; end if; end myTRIGGER;
2
22713
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 format. I'm trying to figure out how to import that into SQL Server 2000 so that I'll be able to manipulate it in a gui format, rather than command line. I can't find any import that takes a .sql file. I've been trying to load it into the query...
10
6369
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 records were still there. The data is entered and editted through the web interface in ASP. The web interface is accessed by anyone who has an account in our database. I am more of a web programmer, not a SQL server administrator, so not very...
7
12131
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 servers using sp_addlinkedserver on both database servers. When I call the Commit API of oledb I get the following error: Error state: 1, Severity: 19, Server: TST-PROC22, Line#: 1, msg:
18
10309
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 date and time, but my script is erroring. '-- Get login date and time cmdLoginDate = Date() cmdLoginTime = Time()
5
5463
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, i think, it will only read past locked resources but will not guarantee the select statement itself not blocking other statements(in my case Insert). According to my knowledge
2
4251
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 statement... INSERT INTO ..dbo.ls_secondary_files (database_name, tl_file_name, tl_applied, lsplanid, lssecid, compression_type) VALUES ('javaweb', 'c:', 'N', 1, 1, 0)
2
9478
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 prod400db.test.meldbf.InventoryHistory However, this insert statement fails: insert into prod400db.TEST.MELDBF.InventoryHistory
4
14140
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 I have two table: - master(id, field1, field2, ...) - detail(id0, id, progr, data, sede, esecutori, brani_autori) in a master-detail relation with "id" as foreign key. The fields of the "detail" table are:
7
1780
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 development server . For example a recursive UDF takes 20s in my development server and 2m in my production server (both with same users load) but my production server it's much hardware powerfull than the other server. I start monitoring an realized...
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10200
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10145
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9021
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5422
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3707
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.