Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 9th, 2004, 09:46 PM
Registered User
 
Join Date: Jun 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default INSERT With a Text field (C#)

Hello, not sure if this is a C# or a SQL posting. I will try here first.

I have a field in the db that is Text datatype. I am trying to insert a record in the following manner.

cmd.CommandText = "INSERT INTO ContributorsJournal "
+ "(ContributorID, CreatedDateTime, EntryDateTime, Entry ) "
+ "VALUES ( @ContributorID, @CreatedDateTime, @EntryDateTime, @Entry )"
+ "SELECT @@identity AS JournalID "
+ "SET NOCOUNT OFF ";

//Add parameters
cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContributorID ", System.Data.SqlDbType.Int, 4, "ContributorID"));
cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CreatedDateTi me", System.Data.SqlDbType.DateTime, 8, "CreatedDateTime"));
cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@EntryDateTime ", System.Data.SqlDbType.DateTime, 8, "EntryDateTime"));
cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Entry", System.Data.SqlDbType.Text, 16, "Entry"));

//Populate the paramters
cmd.Parameters["@ContributorID"].Value = this.cmContributorID;
cmd.Parameters["@CreatedDateTime"].Value = DateTime.Now;
cmd.Parameters["@EntryDateTime"].Value = DateTime.Now;
cmd.Parameters["@Entry"].Value = this._journalEntry.ToString();

The Entry value (string) always gets truncated.

Any ideas??

Keith
 
Old January 10th, 2004, 11:18 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Does it always get truncated to 16 characters? The "Length" argument in the SqlParameter constructor is the length of the field. Is your "Entry" field only 16 characters?

Also, I noticed something in your query. I think you need a semi-colon inside the query between the end of the "INSERT..." and beginning of "SELECT @@IDENTITY...":
cmd.CommandText = "INSERT INTO ContributorsJournal "
+ "(ContributorID, CreatedDateTime, EntryDateTime, Entry ) "
+ "VALUES ( @ContributorID, @CreatedDateTime, @EntryDateTime, @Entry );"
+ "SELECT @@identity AS JournalID "
+ "SET NOCOUNT OFF ";


Peter
------------------------------------------------------
Work smarter, not harder.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert Text(Sql Server Text Field) to Image(JPG) srinivas72 ADO.NET 2 February 13th, 2009 06:31 PM
Using a form field to direct an INSERT INTO SQL GusGray Access VBA 2 January 25th, 2008 09:50 AM
multiple values insert into one field mateenmohd Classic ASP Basics 0 May 29th, 2007 02:11 AM
insert text into a text box by selecting an link gavmc Other Programming Languages 0 February 15th, 2006 09:46 AM
asp style insert field knight PHP Databases 0 February 4th, 2005 01:51 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.