Web Forms :: Insert Query Error - String Or Binary Data Would Be Truncated

Jul 16, 2012

this is my ImageButton event code

protected void ImageButton_Click1(object sender, ImageClickEventArgs e)
string data = Server.UrlDecode(Request.QueryString["BehCode2"])
SqlCommand _cmd = new SqlCommand("insertinfo", _cn);
_cmd.CommandType = CommandType.StoredProcedure;


View 1 Replies

Similar Messages:

SQL Server :: Error: String Or Binary Data Would Be Truncated?

Mar 23, 2011

Whenever I add more than a very short string to the "description" column in my table I get this error. That column (in the DVD table) is set to NVARCHAR(1000). I can't see what the problem is. I've add the procedure that throws exception below.

System.Data.SqlClient.SqlException was unhandled by user code
Message="String or binary data would be truncated.
The statement has been terminated."
Source=".Net SqlClient Data Provider"


View 3 Replies

ADO.NET :: Error 'String Or Binary Data Would Be Truncated" When Trying To Upload An Image

Nov 9, 2010

I am getting the error: String or binary data would be truncated. The statement has been terminated. when trying to upload an image. What would cause this? my code is:

protected void Button1_Click(object sender, EventArgs e)
if (IsPostBack)
string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
System.Data.SqlClient.SqlConnection sqlConnection1 =
new System.Data.SqlClient.SqlConnection(connectionString);
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "INSERT INTO picstosort (imageurl, useraddy) VALUES (@imageurl, @useraddy)";
cmd.Parameters.AddWithValue("@imageurl", Label5.Text);
cmd.Parameters.AddWithValue("@useraddy", TextBox1.Text);
cmd.Connection = sqlConnection1;
if (TextBox1.Text != null)
string strTo = TextBox1.Text;
string strFrom = "noreply@test.com";
string strSubject = "Picture Uploaded";
SmtpMail.Send(strFrom, strTo, strSubject,
"Thank you for uploading your picture! ");
private void HandleUploadedFile()
string root = Server.MapPath("~/");
if (!root.EndsWith(@""))
root +=@"";
string fileDirectory = root + @"Images";
string link = "<a href='Images/{0}' target='_blank'>{1}</a>{2}{3}";
for (int i = 0; i<Request.Files.Count; i++)
HttpPostedFile fi = Request.Files.Get(i);
byte[] fileBytes = new byte [fi.ContentLength];
using (System.IO.Stream stream = fi.InputStream)
stream.Read(fileBytes, 0, fi.ContentLength);
string fileName = Guid.NewGuid().ToString();
File.WriteAllBytes(fileDirectory + fileName + "_small.jpg",
ResizeImageFile(fileBytes, 10000));
litText.Text += string.Format(link, fileName + "_small.jpg",
fileName + " Small", "<br/>", "<br/>");
Label5.Text = fileDirectory + fileName + ".jpg";
litText.Visible = true;
fileBytes = null;
private static byte[] ResizeImageFile(byte[] imageFile, int targetSize)
using (System.Drawing.Image oldImage = System.Drawing.Image.FromStream(new MemoryStream(imageFile)))
Size newSize = CalculateDimensions(oldImage.Size, targetSize);
using (Bitmap newImage = new Bitmap(newSize.Width, newSize.Height, PixelFormat.Format24bppRgb))
using(Graphics canvas = Graphics.FromImage(newImage))
canvas.SmoothingMode = SmoothingMode.AntiAlias;
canvas.InterpolationMode = InterpolationMode.HighQualityBicubic;
canvas.PixelOffsetMode = PixelOffsetMode.HighQuality;
new Rectangle(new Point(0, 0), newSize));
MemoryStream m = new MemoryStream();
newImage.Save(m, ImageFormat.Jpeg);
return m.GetBuffer();
private static Size CalculateDimensions(Size oldSize, int targetSize)
Size newSize = new Size();
if (oldSize.Height > oldSize.Width)
newSize.Width = (int)(oldSize.Width * ((float)targetSize / (float)oldSize.Height));
newSize.Height = targetSize;
newSize.Width = targetSize;
newSize.Height =
(int)(oldSize.Height * ((float)targetSize / (float)oldSize.Width));
return newSize;

View 3 Replies

String Or Binary Data Would Be Truncated - The Statement Has Been Terminated

Nov 11, 2010

String or binary data would be truncated. The statement has been terminated. I'm using the following code but some times(not all the time) i get the above error ....

View 2 Replies

DataSource Controls :: String Or Binary Data Would Be Truncated?

Jan 8, 2010

I tested my app locally and it works perfect, but as soon I publish it, upload it to server and try it, on a 100% copy of my local database it throw me a truncate message; now via this msg

that throws me the error query or via sql profiler I got this query:


View 1 Replies

File Upload String Or Binary Data Would Be Truncated

May 17, 2010

I have a website that uploads different file types, creates thumbs from the files and saves the file and thumbs to their respective folders. every so often it throws an exception string or binary data would be truncated, Ive never encountered this locally. I have a problem pinning down the circumstances that it happens, I thought it was documents with spaces in the name but that works sometimes as well. This is really bugging me and I need to fix this. The db table fields are long enough, trust me . Has anyone else ever encountered this issue?

View 1 Replies

C# - String Or Binary Data Would Be Truncated. The Statement Has Been Terminated

Apr 9, 2010

I have a SqlCommand object on my c# based asp.net page. The SQL and the passed parameters are working the majority of the time. I have one case that is not working, I get the following error:

String or binary data would be truncated. The statement has been terminated.

I understand the error and but all the columns in the database should be long enough to hold everything being sent.

Is there a way to see what the actual SQL being sent to the database is from SqlCommand object? I would like to be able to email the SQL when an error occurs.

View 4 Replies

DataSource Controls :: Sql Server String Or Binary Data Would Be Truncated?

Feb 11, 2010

I am using Sql server version enterprise edition 9 on win NT.I have an issue with the stored procedure, when I execute the SP I get an error message "String or binary data would be truncated." In general I know that we get this error when the inserted value is greater than the column length, but in this scenario the SP is failing only the for the section 1 insertion. The same SP contains one more section where we are inserting records in to same table from same source table based on some different condition and it works.I wrote a script in which I copied the section from the SP which has the problem and storing the output of it in an temp table and inserting one by one record using cursors in to the destination table and then it works.I tried with the option SET ANSI_WARNINGS OFF and SET ANSI_NULLS ON, but it did not work. I am sure that it is not failing because of the length of the data inserted.Is there are other configuration that i can set??

View 1 Replies

Data Controls :: File Upload - String Or Binary Data Would Be Truncated

Jun 20, 2013

I uploaded above 10 mb file i am getting this error..

"String or binary data would be truncated. The statement has been terminated"

my datatype in database is set as varbinary(MAX) then also i am geeting error

View 1 Replies

Data Controls :: String Or Binary Data Would Be Truncated - The Statement Has Been Terminated

Mar 26, 2016

CREATE TABLE [dbo].[login] (
[username] NCHAR (10) NOT NULL,
[password] NCHAR (10) NOT NULL,
[Phone_no] NVARCHAR (50) NOT NULL,

[Code] ....

When I am trying to save the value then get above mentioned error ....

View 1 Replies

Data Controls :: DropDownLists - String Or Binary Data Would Be Truncated

Mar 4, 2013

I have 2 DropDownList and 1 button  in admin.aspx page

1=DDLtradeO and 2=DDLclassO

users should select Item from both of them I use RequiredFieldValidator for both of them and when they click on button in HOuse_info Table it insert their data here when users select first item from DDLtradeO  (that text is="State" )

{ DDLclassO.Enable=false}

below is code

<asp:DropDownList ID="DDLtradeO" runat="server" CssClass="DPCDDLs" AutoPostBack="true" OnSelectedIndexChanged="DDLtrade_SIC">

and behind code

protected void DDLtrade_SIC(object sender, EventArgs e) {
if (DDLtrade.SelectedItem.Text != "State") {
DDLclass.Enabled = true;
Rfv11.Visible = true;
} else {
DDLclass.Enabled = false;
Rfv11.Visible = false;

here RFV11 is RequiredFieldValidator for DDlclasso..problem is here when users select other item from DDltradeO and they select Item form DDLcalssO when they click on button it insert data into House_info table correctly but when they select "STATE" Item from DDLtradO (they can't select Item from DDlcalssO) when they click button this error occurrence Server Error in '/behtop website' Application.

String or binary data would be truncated. The statement has been terminated.An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details:  System. Data. SqlClient.SqlException: String or binary data would be truncated. The statement has been terminated. Source Error: 

Line 312:
Line 313:
Line 314: int result = Convert.ToInt32(_cmd.ExecuteScalar()); Line 315: _cn.Close();
Line 316: //LBLERROR.Text = _cmd.Parameters["@Success"].Value.ToString();

I think its depend to RequiredFieldValidator but I want if users select other Item from DDltrade they select Item from DDLcalssO. Server Error in '/behtop website' Application.

String or binary data would be truncated.The statement has been terminated. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: String or binary data would be truncated. The statement has been terminated. Source Error: 

Line 312:
Line 313:
Line 314: int result = Convert.ToInt32(_cmd.ExecuteScalar()); Line 315: _cn.Close();
Line 316: //LBLERROR.Text = _cmd.Parameters["@Success"].Value.ToString();

View 1 Replies

Forms Data Controls :: DetailsView Insert Into Table And Query String?

May 7, 2010

I am passing a query string into a new page and want a detailsview to insert whatever comments a user enters

I am getting an error AlbumUID does not accept nulls error.

I thought I passed the query string value to the insert statement but I must have missed something

Here's what I have:

<asp:SqlDataSource ID="SqlDSAddComment" runat="server"
ConnectionString="<%$ ConnectionStrings:MyCDsConnectionStringHome %>"
InsertCommand="INSERT INTO [Comments] ([Comments], [Rating], [AlbumUID]) VALUES (@Comments, @Rating, @AlbumUID)"


View 6 Replies

Web Forms :: Error In Retrieving Data From Database Using Query String For Having In Table

May 18, 2012

I am using query string under gridview, when i click link on gridview "

Datas are in table,


Educational aides-Glass Decorators  (Display the value in search related page)

Colleges-Arts & Science Colleges UG/PG (does not display the value because (&)

 My coding

<asp:GridView ID="GridView2" GridLines="none" runat="server" AutoGenerateColumns="false" >
<a href="search_related.aspx?id=<%# Eval("add_cat_name")%>">

[Code] .....

View 1 Replies

C# - How To Write Binary Data "as Is" To Registry (ie: I Have Visible Binary Data As String From Regedit Only)

Feb 23, 2011

I have been googling this and have not come along a working solution for an entire day. I don't know anything about binary data types (as I've never knowingly used them) and I'm trying to write a binary value that I see in the registry, to the registry. Now, all I see is the following [shown below]... and if I try to pass that as a string to the RegSetValueEx in the WinAPI and of course it errors out... I do not know what 'numbers' I need to pass into the lpData As Any, argument of RegSetValueEx (i tried a bit array) in order for it to come out as the following [shown below] in the regedit. I really have no idea, and my tests to place random numbers in the bit array just produce corresponding random "figures" as visible in regedit that I do not understand how to 'tie' them together logically.

here is the culprit!


If I had the following in a string or a bit array, what must I populate the bitarray with so that the registry outputs this [above] when written? or, how can I figure out how to do it? I was hoping there'd be a function that reads my string of binary data and transforms it into the real binary format to submit to the RegSetValueEx function in VB6 or other function in VB.Net or C# (this really is a language agnostic question, and the problem exists in all languages; ie: same process).

View 2 Replies

Insert Array From Query String Into SQL 2005?

Oct 6, 2010

I am trying to insert an array into SQL with no luck. I get the string from a GPRS device that looks like this:

/WeightBridge.aspx?ReadeID=A1B5A0F5C4E4A1B5A0F5C4E4&TagID=45B6C56A90B645B6C56A90B6,A47B1256A45F0843,B49B1256A45F08FF,30 SEP 2010 21:33:59,I,&Custom=Vehicle Num

All I want to do is to split the TagID array and insert it with the rest of the string into a SQL table. The TagID array must inserted into the following colomns in the DB. TagID, TID, UserMemory, DateTime and Direction. After the insert I just give a response that the insert was successfull or failed. Thank you

My code this far:


View 1 Replies

SQL Server :: Set The Query String Value In An Insert Parameter?

Nov 21, 2010

I have a stored procedure that is close to working. It takes the values of a details view puts them into the respective table 'entity' then should also put the @@identity into 'entloan' and should put the LoanID which is in the query string of the page the detials view is loaded on, into the LoanID field of entLoan as well. Everything works except for getting the querystring value to pass to a insert variable on my stored procedure.

Stored Procedure


I do not have a LoanID Insert parameter set as it is not in entity table:


I have been playing around with different code in the backend but always get errors:


View 2 Replies

Will CLOB Data Be Truncated When Displayed In A Select Query? If So, How Can It Be Displayed

Jul 1, 2010

I've got a Varchar2 field in my table which I want to convert to a CLOB. I am unsure whether the data would get truncated when selected. If so, what is the limit and does it depend on the database settings?

In my TOAD or SQLPLUS window it gets truncated but this may just be the environment settings. I'm not sure whether it would get truncated in my actual application (I can test this, but up to what size should I test?)

If it does get truncated, what's the best way to display the whole CLOB? There are other fields in my SELECT query, so I think I can't just loop through multiple rows. Is there any way out?

View 2 Replies

DataSource Controls :: String Is Truncated When Inserted Into DB?

Feb 10, 2010

I am trying to insert some string values into database.

The problem here is that, the string is truncated without warning..

Here is my vb.net code


And here is how I declared the varible in stored procedure


And If I insert "myCode01234567890" then it's truncated without warning at all.

How can I let it throw an exception rather then truncate the string without any warnings ?

View 9 Replies

Javascript - Display A Truncated String Using Eval

Jul 29, 2010

I have a ASP gridview control. I have a ASP label control in the item template column. I bind data to the grid using -

<asp:Label ID="lblDesc" runat="server" Text='<%# Eval("Description") %>'></asp:Label>

But, the value of this string can be upto 80 characters. But, I cannot afford to have the column length to be so high. And, there are limitations so I cannot use Wrap="true" and limit the column width. So, I figured the solution could be to display only about 50 characters in the grid and display the entire string as a tool tip. I managed to do this by using this -

<asp:Label ID="lblDesc" runat="server" Text='<%# Eval("Description").ToString().Substring(0,50) %>' ToolTip='<%# Eval("Description") %>'></asp:Label>

This displays the first 50 characters of the string in the grid column. And, the complete string is displayed as a tool tip when the mouse pointer hovers over the text. But, the problem arises when the string length is less than 50 characters. In this case, an exception is thrown. I tried modifying this piece of code to allow conditional display by checking for the string length. But, I could not get this to work. Is there a way to fix this problem? Can we call a javascript function within Eval() ?

View 2 Replies

Forms Data Controls :: Insert On Details View Causes Error Cant Insert Null Into Primary Key Field?

May 22, 2010

I am using Visual studio 2010 express and I have a details view databinded to an sql database table. When I use the Insert option on the view it causes an error due to it trying to insert a null into the primary key field. If the Insert function does not create a new primary key entry how is it created?

View 9 Replies

Insert Record Into MSAccess Table - Syntax Error (missing Operator) In Query Expression

Mar 19, 2016

As I am learning asp.net . when i try to insert record into msaccess table why it says -

Syntax error (missing operator) in query expression 'user1','cx0437@gmail.com' ,'12312456')'.

As i found the same code at the following link [URL] ....

protected void Button1_Click(object sender, EventArgs e) {
OleDbConnection con;
using (con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;" + @"DATA SOURCE=C:Database iershop.mdb")) {

[Code] ....

View 1 Replies

Possible To Convert Datatable Into Binary Data And Save It Into On Binary Field On Database

Sep 20, 2010

Is it possible to convert a datatable into binary data and save it into on a binary field on database?

View 2 Replies

SQL Server :: How To Build Long Query String Error / Too Many Characters In Character Literal

Sep 23, 2010

I know that it is basic questions, but I am stuck here.

I have TableOne have fields: USERNAME, PID, GID, TID, SID, NEWSID. I need to write query string to check if those value is already in the table. If not, insert those value to the table.


However, I got the many errors:

Error 1 Too many characters in character literal

Error 3 Newline in constant

View 3 Replies

Query To Retrieve Binary Image On Load?

Sep 21, 2010

Is there such a thing? So for eample, on my image load I have the following hooked up to a table where "Image" is a binary image set of data.

protected void Image1_Load1(object sender, EventArgs e)
myent logo = new myent();
var query = (from p in logo.tblLogoes
where p.Id == id && p.Id2 == id2
select p.Image).First();
return query.

What do I need to return here to populate the image? I have funny feeling, it's not going to be as simple as that.

View 1 Replies

Forms Data Controls :: Populate INSERT Query From Gridview DropDownList?

Apr 21, 2010

I have a Gridview which I'm populating through code behind. A couple of columns of the gridview I've set up to be drop down lists. What I want, is that when I run my Insert query, it takes the drop down list selected value, finds the appropriate ID and uses that ID as part of the insert query.

Below is my select and insert query.


This is the related asp:


View 22 Replies

Copyrights 2005-15 www.BigResource.com, All rights reserved