Data Getting Truncated As I Insert I.e. Instead Of Inserting Hello It Inserts 'H'
Jul 25, 2005
m inserting some data in big-sized field
and small-sized fields, data of varchar type, int's, dateTime, and
others... i am using something called a stored procedure to add data
into a table.. now when i execute the stored procedure my data gets
truncated (although i made the sizes for my fields ridiculously big
like 1000 just in case) for example if i want to enter Jasmine it only
inserts 'J' in the field
I am sure there's something wrong in the stored procedure, and I am
guessing it's a problem of using single vs. double quotes and stuff
like that within my insert statement...
the following is my stored procedure:
CREATE procedure addLabor
@lName varchar,
@fName varchar,
@mName varchar,
@title varchar,
@craft varchar,
@lastFour varchar,
@SSN varchar,
@dateOfHire varchar,
@currentProj varchar,
@status tinyInt,
@project_id int,
@updateBy varchar,
@updateDate varchar,
@address varchar,
@email varchar,
@phone varchar,
@zip varchar,
@myfeedBack varchar,
@ethnicity varchar,
@userID int
as
BEGIN
SET NOCOUNT OFF
DECLARE @newid INT
insert into laborPersonal ( lName, fName, mName, title, craft,
lastFour, SSN, dateOfHire, currentProj, status, project_id,
updateBy,
updateDate, address, email, phone, zip, ethnicity)
VALUES
(@lName , @fName , @mName , @title , @craft , @lastFour , @SSN ,@dateOfHire , @currentProj ,
@status, @project_id , @UpdateBy, @UpdateDate , @address , @email , @phone , @zip , @ethnicity )
SELECT @newid = SCOPE_IDENTITY()
insert into feedBack
(lID, feedBack, userID, project_id)
values
(@newid ,+'
+@myfeedBack + ',
+@userID ,
@project_id )
SET NOCOUNT ON
END
GO
When i use 2 single quotes it insert the following string: "@lName" not the actual value of the variable @lName
my exec statement is this:
EXEC addLabor 'Razor', 'Nazor', 'mid', 'Mr', 'Carpenter Forman',
'1234',
'keOWVozC+wmBvaqgkVkZci5y4vFLdTKfZOVG4C6BSN6H2MBP6pdsIWA0SdPAlPJra0EjEj+uXI/kXSiBuwwnKQ==',
'6/27/2005 12:00:00 AM' , 'O.C. Public Library', 1, 3, '3', '7/25/2005
2:38:02 PM', '1233 Shady Canyon, Irvine', '', '', '12345',
'123-12-1234', 'African American', '3'
I appreciate any help or hints
thanks to all
View 1 Replies
ADVERTISEMENT
Jan 10, 2007
Hi everyone. Does anyone know if you can retrieve truncated data from a BULK INSERT operation?
We have a file that needs to be inserted into a SQL Server Database. There is a field that has a maximum of 8000 characters, but some times users submit files that have more than that. We need to be able to capture the truncated data. The BULK INSERT operation does not throw an error. The only way I can think of to get the data is if I bulk insert the data into a temporary table with a memo field and then copy it over, but that may really slow down the SP.
Has anyone encountered this situation before? I also have the option of parsing the file in .NET.
Thanks and take care,
Angel
View 9 Replies
View Related
Aug 22, 2006
Hi there,
I'm having a problem where the data taken from the textboxes is being inserted into a table twice. I looked online and someone on another forum was experiencing the same problem. His solution was making the "submitdsabledcontrols" attribute of the form false. That hasn't fixed the issue for me.
Below is my code. I'm still learning all this so this is just a test page, hence the wacky naming conventions.
When the button click calls Button1_Click, all it runs is "SqlDataSource1.Insert()"
Any ideas?
<%@ Page EnableEventValidation="false" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Default3.aspx.vb" Inherits="Default3" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="mainContent" Runat="Server">
<form id="form1" submitdisabledcontrols=false>
<br />
<asp:Label ID="Label1" runat="server">Name</asp:Label>
<asp:TextBox ID="NameTextBox" runat="server"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Label">Number</asp:Label>
<asp:TextBox ID="NumberTextBox" runat="server"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label3" runat="server" Text="Label">Salary</asp:Label>
<asp:TextBox ID="SalaryTextBox" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_click" />
</form>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:pubsConnectionString1 %>" DeleteCommand="DELETE FROM [Table1] WHERE [TableID] = @original_TableID" InsertCommand="INSERT INTO [Table1] ([Name], [Number], [Salary]) VALUES (@Name, @Number, @Salary)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [Table1]" UpdateCommand="UPDATE [Table1] SET [Name] = @Name, [Number] = @Number, [Salary] = @Salary WHERE [TableID] = @original_TableID">
<DeleteParameters>
<asp:Parameter Name="original_TableID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Number" Type="String" />
<asp:Parameter Name="Salary" Type="Decimal" />
<asp:Parameter Name="original_TableID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:ControlParameter Name="Name" Type="String" ControlID="NameTextBox" />
<asp:ControlParameter Name="Number" Type="String" ControlID="NumberTextBox" />
<asp:ControlParameter Name="Salary" Type="decimal" ControlID="SalaryTextBox" />
</InsertParameters>
</asp:SqlDataSource>
</asp:Content>
View 1 Replies
View Related
Feb 13, 2001
Hi, got this sql statement, I am not sure why I am getting this error message at the botton. Thanks for your input:
insert into generator(member_id,contact_id,company_name,contac t_fname)
select member_id,contact_id,company_name,contact_fname
from customer
Server: Msg 8152, Level 16, State 9, Line 1
String or binary data would be truncated.
The statement has been terminated.
Thanks
View 1 Replies
View Related
Apr 19, 2007
Hi folks,
After getting a form view inserting some values into a mdb file, it inserts the same values a second time on page reload.
How may I cure this? Any suggestions?
VB Code is below.
many thanks in advance
Rosi
1 <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="km_Eingabe.aspx.vb" Inherits="km_Eingabe" title="km-Eingabe" %>
2 <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
3 <table style="width: 750px; height: 210px">
4 <tr>
5 <td style="height: 38px">
6 </td>
7 <td style="height: 38px">
8 <asp:DropDownList ID="dropdownlist1" runat="server" AutoPostBack="True" DataSourceID="AccessDataSource2"
9 DataTextField="polKennz" DataValueField="polKennz">
10 </asp:DropDownList>
11 </td>
12 <td style="height: 38px">
13 </td>
14 </tr>
15 <tr>
16 <td style="height: 235px">
17 </td>
18 <td style="height: 235px" valign="top">
19
20 <asp:FormView ID="FormView1" runat="server" CellPadding="4" DataSourceID="SqlDataSource1"
21 ForeColor="#333333">
22 <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
23 <EditRowStyle BackColor="#999999" />
24 <EditItemTemplate>
25
26 </EditItemTemplate>
27 <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
28 <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
29 <EmptyDataTemplate>
30 keine Daten vorhanden
31 <br />
32 <asp:LinkButton ID="NewButton" runat="server" CommandName="New" Text="Neuer Eintrag"></asp:LinkButton>
33 </EmptyDataTemplate>
34 <InsertItemTemplate>
35 Datum:
36 <asp:TextBox ID="DatumTextBox" runat="server" Text='<%# Bind("Datum", "{0:d}") %>'>
37 </asp:TextBox>
38 <br />
39 Fahrer:
40 <asp:TextBox ID="FahrerTextBox" runat="server" Text='<%# Bind("Fahrer") %>'>
41 </asp:TextBox>
42 <br />
43 polKennz:
44 <asp:TextBox ID="polKennzTextBox" runat="server" Text='<%# Bind("polKennz") %>'>
45 </asp:TextBox>
46 <br />
47 neuer_Eintrag:
48 <asp:TextBox ID="neuer_EintragTextBox" runat="server" Text='<%# Bind("neu") %>'></asp:TextBox>
49 <br />
50 aktuell:
51 <asp:TextBox ID="aktuellTextBox" runat="server" Text='<%# Bind("aktuell") %>'></asp:TextBox> <br />
52 <br />
53 <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
54 Text="Einfügen" OnClick="InsertButton_Click">
55 </asp:LinkButton>
56 <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
57 Text="Abbrechen">
58 </asp:LinkButton>
59 </InsertItemTemplate>
60 <ItemTemplate>
61 Datum:
62 <asp:Label ID="DatumLabel" runat="server" Text='<%# Bind("Datum") %>'></asp:Label><br />
63 Fahrer:
64 <asp:Label ID="FahrerLabel" runat="server" Text='<%# Bind("Fahrer") %>'></asp:Label><br />
65 polKennz:
66 <asp:Label ID="polKennzLabel" runat="server" Text='<%# Bind("polKennz") %>'></asp:Label><br />
67 neu:
68 <asp:Label ID="neuLabel" runat="server" Text='<%# Bind("neu") %>'></asp:Label><br />
69 lfdNr:
70 <asp:Label ID="lfdNrLabel" runat="server" Text='<%# Eval("lfdNr") %>'></asp:Label><br />
71 aktuell:
72 <asp:Label ID="aktuellLabel" runat="server" Text='<%# Bind("aktuell") %>'></asp:Label><br />
73 Dienststelle:
74 <asp:Label ID="DienststelleLabel" runat="server" Text='<%# Bind("Dienststelle") %>'></asp:Label><br />
75 <asp:LinkButton ID="NewButton" runat="server" CommandName="New" Text="Neuer Eintrag"></asp:LinkButton>
76 </ItemTemplate>
77 <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
78 </asp:FormView>
79 </td>
80 <td style="height: 235px">
81 </td>
82 </tr>
83 <tr>
84 <td>
85 </td>
86 <td>
87 </td>
88 <td>
89 </td>
90 </tr>
91 </table>
92 <asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/KfzDaten_Ansicht.mdb"
93 SelectCommand="SELECT DISTINCT [polKennz] FROM [qry_KennzeichenAlle_ohne_ausgesondert]">
94 </asp:AccessDataSource>
95 <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/KfzDaten_Ansicht.mdb"
96 SelectCommand="SELECT DISTINCT [Datum], [Nutzer], [Fahrer], [polKennz], [aktuell], [neu], [gefahren] FROM [qry_Fahrtenbuch_letzter_Eintrag_pro_Kfz] WHERE ([polKennz] = ?)">
97 <SelectParameters>
98 <asp:ControlParameter ControlID="DropDownList1" Name="polKennz" PropertyName="SelectedValue"
99 Type="String" />
100 </SelectParameters>
101 </asp:AccessDataSource>
102 <asp:SqlDataSource ID="SqlDataSource1" DataSourceMode="DataSet" ConflictDetection="CompareAllValues" InsertCommandType="Text" runat="server" ConnectionString="<%$ ConnectionStrings:KfzDaten_Ansicht_mdbConnectionString %>" ProviderName="<%$ ConnectionStrings:KfzDaten_Ansicht_mdbConnectionString.ProviderName %>"
103 InsertCommand= "INSERT INTO Tab_import_Fahrtenbuch([Datum], [Fahrer], [polKennz], [neu], [aktuell]) VALUES (@Datum, @Fahrer, @polKennz, @Eingabe_neu, @Eingabe_aktuell )" >
104 <SelectParameters>
105 <asp:ControlParameter ControlID="dropdownlist1" Name="newparameter" PropertyName="SelectedValue" />
106 </SelectParameters>
107 <InsertParameters>
108 <asp:FormParameter FormField="DatumTextBox" Name="Datum" Type="string" />
109 <asp:FormParameter FormField="FahrerTextBox" Name="Fahrer" Type="string" />
110 <asp:FormParameter FormField="polKennzTextBox" Name="polKennz" Type="string" />
111 <asp:FormParameter FormField="neuer_EintragTextBox" Name="neu" Type="Int32" ConvertEmptyStringToNull="false" />
112 <asp:FormParameter FormField="aktuellTextBox" Name="aktuell" Type="Int32" ConvertEmptyStringToNull="false" Direction="Input" />
113 </InsertParameters>
114 </asp:SqlDataSource>
115
116 </asp:Content>
117
118
View 5 Replies
View Related
Oct 6, 2007
the error message I get is
{"Object reference not set to an instance of an object."}
and it points to < Tickr As String = CType(FindControl("TickerTextbx"), TextBox).Text >
this is my code":
Protected Sub TickMastBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TickMastBtn.Click
REM Collect variablesDim Tickr As String = CType(FindControl("TickerTextbx"), TextBox).Text
Dim Comp As String = CType(FindControl("CoTextbx"), TextBox).TextDim Exch As String = CType(FindControl("ExchTextbx"), TextBox).Text
REM Create connection and command objectsDim cn As New SqlConnection("Data Source=.SQLEXPRESS;AttachDbFilename=C:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLDataVTRADE.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")Dim cmd As New SqlCommand
cmd.Connection = cn
REM Build our parameterized insert statementDim sql As New StringBuilder
sql.Append("INSERT INTO TickerMaster ")sql.Append("(Ticker,Company,Exchange,) ")sql.Append("VALUES (@Tickr,@Comp,@Exch,)")
cmd.CommandText = sql.ToString
REM Add parameter values to command
REM Parameters used to protect DB from SQL injection attacksWith cmd.Parameters
.Add("Tickr", SqlDbType.Int).Value = Tickr.Add("Comp", SqlDbType.VarChar).Value = Comp
.Add("Exch", SqlDbType.VarChar).Value = Exch
End With
REM Now execute the statement
cn.Open()
cmd.ExecuteNonQuery()
cn.Close()
End Sub
View 3 Replies
View Related
Sep 29, 2007
Hi,
I have a data file in the folloing format
SubjectId1|class1
SubjectId2|class2
SubjectId3|class3
I just wanted to insert only SubjectIds into my table 'Subjects' which has the follwing schama ignoring the classes
The row delimeter is "
" and the column delimeter is ' | '
Table Subjects
{
ID (Autoincrement)
SubjectId varchar(20)
}
Can any one provide the format file for doing this or suggest anyway to do this?
Please do note that the file may contain millions of records
Thank u
~mohan
View 5 Replies
View Related
Oct 10, 2007
Hi,
I have a data file which consists of data as below,
4
PPU_FFA7485E0D||
T_GLR_DET_11||
While iam inserting into table using bulk insert, this pipe(||) is also getting inserted into the table,
here is my query iam using to insert the data using bulk insert.
BULK INSERT TABLE_NAME FROM FILE_PATH
WITH (FIELDTERMINATOR = ''||'''+',KEEPNULLS,FIRSTROW=2,ROWTERMINATOR = '''')
Can any one help on this.
Thanks,
-Badri
View 7 Replies
View Related
Nov 29, 2007
Hello all,
I have a COM object (written in VB6) that uses the Microsoft Remote Data Object 2.0 (MSRDO20.dll) to perform non-exotic SQL statements (i.e. SELECTs, INSERTs, UPDATEs and DELETE).
I am using SQL Server 2000 with SP4.
Some of our INSERT statements are being truncated within SQL2K...
We have turned on the SQL Profiler to verify this. Using our own logging mechanism, we log the INSERT SQL being passed to SQL2K immediately before executing the MS SQL statement and our log shows that the INSERT statement is indeed correct. However, we get a SQL error back due to malformed SQL. The SQL Profiler shows that the last 10 bytes have been truncated from the INSERT SQL within SQL2K.
The INSERT statement that we are passing is in the following form...
INSERT (column names...) VALUES (...)
There are embedded CRs (0x0D) in the INSERT.
The length of the INSERT being passed to SQL2K is 2243 bytes.
The length of the INSERT from the Profiler is 2233 bytes (the last 10 bytes were truncated).
Here's a brief glimpse of our VB6 code...
Dim Cn as rdoConnection
Dim sSql as String
Set Cn = New rdoConnection
Cn.Connect = "DSN=FrontOff;UID=Front;PWD=Front;DATABASE=FrontOff;"
Cn.CursorDriver = iCursorDriver
Cn.LoginTimeout = 5
Cn.QueryTimeout = 5
Cn.EstablishConnection rdDriverNoPrompt
sSql = "INSERT INTO PLU €¦"
Cn.QueryTimeout = 300
// Log sSQL to our logging mechanism...
Cn.Execute sSql, rdExecDirect
So, is there a maximum length for a SQL statement in SQL2K???
Any help would be appreciated.
TIA!!!
View 1 Replies
View Related
Mar 18, 2007
I currently insert into one table with: SqlCommand comm = new SqlCommand("INSERT INTO UsersTable (UserName, Password, Email) VALUES (@person, @pass, @email)", sqlConnection); comm.Parameters.AddWithValue("@person", usrnmeLbl.Text); comm.Parameters.AddWithValue("@pass", hiddenpassLbl.Text); comm.Parameters.AddWithValue("@email", hemailLbl.Text);but I realized that there's another table related to this table and I need to have something go in it so that the users data will be recorded at the same pace. So I tried: SqlCommand comm = new SqlCommand("INSERT INTO UsersTable, FatherHistTable (UserName, Password, Email), (Father) VALUES (@person, @pass, @email), (@father)", sqlConnection); comm.Parameters.AddWithValue("@person", usrnmeLbl.Text); comm.Parameters.AddWithValue("@pass", hiddenpassLbl.Text); comm.Parameters.AddWithValue("@email", hemailLbl.Text); comm.Parameters.AddWithValue("@father", fthrsNmeLbl.Text);Not working, so I am thinking I must do two inserts: SqlCommand comm = new SqlCommand("INSERT INTO
UsersTable (UserName, Password, Email) VALUES (@person, @pass,
@email)", sqlConnection);
comm.Parameters.AddWithValue("@person", usrnmeLbl.Text);
comm.Parameters.AddWithValue("@pass", hiddenpassLbl.Text);
comm.Parameters.AddWithValue("@email", hemailLbl.Text); SqlCommand comm2 = new SqlCommand("INSERT INTO
FatherHistTable (Father) VALUES (@father)", sqlConnection);
comm2.Parameters.AddWithValue("@father", fthrsNmeLbl.Text); Is that the only way to go about it then? Thanks in advance for any explanations.
View 26 Replies
View Related
Mar 14, 2006
Hi,Question: Why is INSERT of a string having 8000+ characters causing truncation in a TEXT field?We are working on a website for a client, and one of their CMS-driven pages contains more than 8000 chars for its content. The database field was originally TEXT datatype at the default size, but the content was getting truncated upon INSERT. So I looked into why this was happening, tried many things including: 1. Executing: EXEC sp_tableoption 'section', 'text in row', '7000'2. Changing datatype from TEXT to VARCHAR(8000). (of course this truncated at 8000).And this truncation still occurring. This is happening on SQL Server 2000 installed and configured on our client's server. The servers we host don't have this problem, and we have even tested the INSERT on our server and it does not truncate. So why is it truncating only on our client's Sql Server? Is there some kind of default configuration setting that limits the allowable length?I'm not intimately familiar with the large BLOB datatypes, and haven't really needed to deal with this issue before now. Now the client is upset about the limitation and does not wish to copy edit the content for their webpage. This is an urgent matter. I need to figure out the problem within a few hours today (it is morning in Europe on Tuesday 14 mar 2006 right now). Thanks in advance.UPDATE: I HAVE RESOLVED THE ISSUE. THE PROBLEM WAS A RESTRICTION IN THE STORED PROCEDURE INPUT VARIABLE DECLARATION -- WAS TRUNCATING AT 8000 CHARACTERS.
View 13 Replies
View Related
May 15, 2008
Greetings
Got bulk insert thing going real nice thanks to your feedback! But now I notice that the BULK INSERT creates 2 identical rows while the flat file has the column headers and then corresponding row, just one row.
Why would it do that. Interestingly if the data file and format file are residing on a shared folder on SQL 2005, and I ran the BULK INSERT from studio it only inserts one row. But when I do BULK INSERT via user interface it creates 2 rows. What is going here.
View 10 Replies
View Related
Oct 18, 2006
When I enter over 4000 chars in any ntext field in my SQL Server 2005 database (directly in the database and through the application) I get an error saying that the data could not be updated because string or binary data would be truncated.Has anyone ever seen this? I cannot figure out what is causing it, ntext should be able to hold a lot more data that this...
View 7 Replies
View Related
May 21, 2008
String or binary data would be truncated. I get this error when entering data using sql server management studio express.
I am not running a sql to insert or update the table. This is through the EDI.
The data type is varchar(100). I enter one character and it errors on me. So this isn't a string being too long problem.
Any ideas?
View 2 Replies
View Related
Feb 21, 2006
When using AquaData or JDBC (inet tds driver), when doing an insert using SqlServer 2005, I get error "String or binary data would be truncated" when the data is actually OK. There are no triggers, etc. that would confuse the situation. It works fine in SqlServer 2000.
The scenario is as follows:
Create table:
create table test3 (
name varchar (18) ,
tbname varchar (18)
)
Create and populate table:
create table maxtable (
tablename varchar (18) not null,
[...]
)
Try to insert into test3:
insert into test3 (name, tbname)
select i.name, o.name
from dbo.sysindexes i, sysobjects o, maxtable m
where i.indid > 0 and i.indid < 255
and i.id = o.id and i.indid = 1
and o.name = lower(m.tablename)
And I get the error "String or binary data would be truncated." The values being selected for i.name and o.name have maximum length of 18. There are other rows in sysindexes and sysobjects with longer values, but they are not being selected.
The error does not occur with SQL Server Management Studio, and does not occur using SqlServer 2000.
View 6 Replies
View Related
Aug 9, 2006
Hi Folks,
After I inserted a row in my Database (row 27) I started getting this error when I try to insert, update or delete the record in the database.
I've searched about the error on google and it says that I should have a field that crossed the limit of characters.
I have only the autoincrement field, two varchar fields and a text field, neither one of the varchar fields crossed the limit, they arent even close. I found in google that one solution would be turn the field that is having problems in a text field, but the only field that actually can be causing the problem already is of the text type.
The exact error I get on VS 2005 when trying to change something in the row 27 is:
"No row was updated.
The data in row 27 was not committed.Error Source: .Net SqlClient Data Provider.Error Message: String or binary data would be truncated.The statement has been terminated.
Corret the errors and retry or press ESC to cancel the change(s)."
I need some help guyz, see ya, hugs.
View 3 Replies
View Related
Jan 21, 2007
Hi Guys, I'm trying to save the data into 2 table when i click the button. But it pops out this error: 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 116:Line 117: Sqlinsert.Connection.Open()Line 118: Sqlinsert.ExecuteNonQuery()Line 119:Line 120: Sqlinsert.Connection.Close() I Don't know what it means so i paste my codes regarding the button & the redline Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
'add the data into shopper
Dim strsqlcmd As String
Dim strName, straddress As String
Dim strContact, strEmail, strPw As String
Dim strIC As String
strName = txtName.Text
straddress = txtAdd.Text
strEmail = txtEmail.Text
strContact = txtboxContact.Text
strIC = txtIC.Text
strsqlcmd = "Insert Into Shopper (Name, Address, Contact, Email, IC) Values (@Name, @Address, @Contact, @Email, @IC)"
SqlCommand1.CommandText = strsqlcmd
With SqlCommand1.Parameters
.Add("@Name", strName)
.Add("@Address", straddress)
.Add("@Contact", strContact)
.Add("@Email", strEmail)
.Add("@IC", strIC)
End With
SqlCnt.Open()
SqlCommand1.ExecuteNonQuery()
SqlCnt.Close()
'add the data into the presc
strsqlcmd = "Insert Into Prescription (Name, Address, Contact, Email, IC) Values (@Name, @Address, @Contact, @Email, @IC)"
Sqlinsert.CommandText = strsqlcmd
With Sqlinsert.Parameters
.Add("@Name", strName)
.Add("@Address", straddress)
.Add("@Contact", strContact)
.Add("@Email", strEmail)
.Add("@IC", strIC)
End With
Sqlinsert.Connection.Open()
Sqlinsert.ExecuteNonQuery()
Sqlinsert.Connection.Close()
' go the add item
Response.Redirect("NewPrescItem.aspx") why my sqlinsert.excutenonquery will have this error? and what is this error really means? Thanks in advance
View 3 Replies
View Related
Sep 12, 2007
I am currently developing a simple program that will upload ms-word documents to a database so users can view them within the department.
The program worked prefectly while using sql 2005 with the these fields:
FormId intFileName nvarchar(50)FileBytes varbinary(Max)
This was done in unit testing, now in system testing there is a difference.
A slight downgrade in the database and server software!
We are using sql 2000 on a 2000 server and the FileBytes datatype had to change to the following:
FormId intFileName nvarchar 50 FileBytes varbinary 8000
There is no 'Max' option in sql 2000 for the datatype varbinary.
So when the insert is perform, we get this error message:
String or binary data would be truncated.The statement has been terminated.
I am guessing it has something to do with FileBytes, because this is the only thing that changed.
I just don't know how to solve the problem.P.S.The application is in ASP.NET 2.0
Thanks,
xyz789
View 4 Replies
View Related
Oct 8, 2007
I keep getting the error "String or binary data would be truncated." when I try to insert data into SQL Sever 2005 from an ASP.net page. Having searched thoughout the web, I know this is generally caused because one of the values being inserted is bigger than the size of the field it's going into. But, I have tested this out in many different ways, and this is not what's causing the problem.
I have tried doing the insert as a SQL statement and using the "ExecuteNonQuery" command. I have also tried running this through a stored procedure. Neither works. In both situations, I have captured the TSQL statements via SQL Profiler and run them in a query window. In both cases, the statements work just fine in a query window.
When I try to do the insert via a stored procedure, all of the statements in the stored procedure show up in SQL Profiler, including the final SELECT statement I have the indicates a successful result. But, the data does not end up in the table and the ASP.net page returns an error.
Also, I have run both the Stored Proceure and the SQL insert statement making all of the fields blank as a way of ensuring that no value can be longer than a field's size. But, in both cases I still get the same error.
Here's the line I use when doing a regular insert:
Dim Command4 = New Data.SqlClient.SqlCommand("INSERT INTO ResourceCenter(UserEmail, UserPassword, Region, FirstName, LastName, Company, JobTitle, Address1, Address2, City, StateProvince, ZipPostalCode, Country, BusinessPhone, WebSiteURL, HowDidYouFind, Industry, WhatTypeOfSolution, CompanySize, NumLogins, LastLogin) VALUES ('" & UserEmail & "', '" & UserPassword & "', '" & Region & "', '" & FirstName & "', '" & LastName & "', '" & Company & "', '" & JobTitle & "', '" & Address1 & "', '" & Address2 & "', '" & City & "', '" & StateProvince & "', '" & ZipPostalCode & "', '" & Country & "', '" & BusinessPhone & "', '" & WebSiteURL & "', '" & HowDidYouFind & "', '" & Industry & "', '', '', 1, " & Now & ")", conn2)
Dim NumRowsUpdated2 = Command4.ExecuteNonQuery()
Here's my code when I call a stored procedure:
Dim dsSignup As New Data.DataSet()Dim Command4 As New Data.SqlClient.SqlDataAdapter("ap_ResourceCenterModify", conn2)Command4.SelectCommand.CommandType = Data.CommandType.StoredProcedureCommand4.SelectCommand.Parameters.Add("@UserID", Data.SqlDbType.Int, 0).Value = 0Command4.SelectCommand.Parameters.Add("@UserEmail", Data.SqlDbType.VarChar, 100).Value = UserEmailCommand4.SelectCommand.Parameters.Add("@UserPassword", Data.SqlDbType.VarChar, 20).Value = UserPasswordCommand4.SelectCommand.Parameters.Add("@Region", Data.SqlDbType.VarChar, 50).Value = RegionCommand4.SelectCommand.Parameters.Add("@FirstName", Data.SqlDbType.VarChar, 100).Value = FirstNameCommand4.SelectCommand.Parameters.Add("@LastName", Data.SqlDbType.VarChar, 100).Value = LastNameCommand4.SelectCommand.Parameters.Add("@Company", Data.SqlDbType.VarChar, 100).Value = CompanyCommand4.SelectCommand.Parameters.Add("@JobTitle", Data.SqlDbType.VarChar, 100).Value = JobTitleCommand4.SelectCommand.Parameters.Add("@Address1", Data.SqlDbType.VarChar, 100).Value = Address1Command4.SelectCommand.Parameters.Add("@Address2", Data.SqlDbType.VarChar, 100).Value = Address2Command4.SelectCommand.Parameters.Add("@City", Data.SqlDbType.VarChar, 100).Value = CityCommand4.SelectCommand.Parameters.Add("@StateProvince", Data.SqlDbType.VarChar, 50).Value = StateProvinceCommand4.SelectCommand.Parameters.Add("@ZipPostalCode", Data.SqlDbType.VarChar, 50).Value = ZipPostalCodeCommand4.SelectCommand.Parameters.Add("@Country", Data.SqlDbType.VarChar, 200).Value = CountryCommand4.SelectCommand.Parameters.Add("@BusinessPhone", Data.SqlDbType.VarChar, 100).Value = BusinessPhoneCommand4.SelectCommand.Parameters.Add("@WebSiteURL", Data.SqlDbType.VarChar, 200).Value = WebSiteURLCommand4.SelectCommand.Parameters.Add("@HowDidYouFind", Data.SqlDbType.VarChar, 100).Value = HowDidYouFindCommand4.SelectCommand.Parameters.Add("@Industry", Data.SqlDbType.VarChar, 100).Value = IndustryCommand4.SelectCommand.Parameters.Add("@WhatTypeOfSolution", Data.SqlDbType.VarChar, 250).Value = WhatTypeOfSolutionCommand4.SelectCommand.Parameters.Add("@CompanySize", Data.SqlDbType.VarChar, 100).Value = CompanySizeCommand4.Fill(dsSignup)Any ideas of what else I can try? Thanks in advance.
View 4 Replies
View Related
Jan 19, 2008
Hi,I am getting the following error:System.Data.SqlClient.SqlException: String or binary data would be
truncated.The statement has been terminated.Can someone tell me what it means?Thanks,Jon
View 2 Replies
View Related
Jan 7, 2004
I am trying to pass a multi lined text field into my SQL Server database. I tried varchar and set the length to 1000 but I still can only pass upto 50 charcters. I also have tried to use other data types like nvarchar, text, and ntext but the text and ntext won't allow me to chenge the length of the field and n varchar will only allow up to 50 charcters no matter how big I make the length. Any help you can give me would be great.
David
View 14 Replies
View Related
Jun 21, 2004
I have a stored proc that inserts binary data into an image field.
I am getting a "String or binary data would be truncated" error when trying to insert large data, but this is *no where* near the maximum size of the image datatype.
Should I be declaring the size of the image parameter in my SQLCommand or something?
TIA,
Mark
Code example:
The sproc:
ALTER PROCEDURE sproc_Content_Insert
(
@ContentName varchar(250),
@ContentDesc varchar(500),
@ContentType varchar(25),
@Content image,
@LocationID int
)
AS
INSERT INTO tbl_Content (ContentName, ContentDesc, ContentType, Content, LocationID)
VALUES (@ContentName, @ContentDesc, @ContentType, @Content, @LocationID)
The method:
Public Sub SaveBinaryContent(ByRef ContentName As String, ByRef ContentDesc As String, ByRef ContentType As String, ByRef Content As String, ByRef LocationID As Integer)
'convert the content to a binary stream.
Dim ms As New System.IO.MemoryStream
Dim bf As New BinaryFormatter
bf.Serialize(ms, Content)
ms.Position = 0
Dim oConn As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim cmd As New SqlCommand("sproc_Content_Insert", oConn)
With cmd
.CommandType = CommandType.StoredProcedure
.Parameters.Add("@ContentName", ContentName)
.Parameters.Add("@ContentDesc", ContentDesc)
.Parameters.Add("@ContentType", ContentType)
.Parameters.Add("@Content", ms.ToArray)
.Parameters.Add("@LocationID", LocationID)
End With
oConn.Open()
cmd.ExecuteNonQuery()
oConn.Close()
oConn.Dispose()
cmd.Dispose()
bf = Nothing
ms = Nothing
End Sub
View 1 Replies
View Related
May 2, 2005
Hi all,
when ever i try uploadin the file to the database, i am facing this weird probs :(
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.Source Error:
Line 124:
Line 125:// Update data source
Line 126:dbAdapt.Update(dbSet,"tblFile1");
Line 127:
Line 128:// Get newFileID
i donno what this means :(
well the code is like this
private void Button1_Click(object sender, System.EventArgs e)
{
HttpPostedFile myFile = filMyFile.PostedFile;
// Get size of uploaded file
nFileLen = myFile.ContentLength;
nFiletype = myFile.ContentType;
// Allocate a buffer for reading of the file
myData = new byte[nFileLen];
// Read uploaded file from the Stream
myFile.InputStream.Read(myData, 0, nFileLen);
strFilename = Path.GetFileName(myFile.FileName);
if( myData.Length != 0)
{
WriteToDB(strFilename,nFiletype,ref myData);
}
}
private int WriteToDB(string strName, string strType, ref byte[] Buffer)
{
int nFileID = 0;
// Create connection
SqlConnection dbConn = new SqlConnection("Data Source=D3BKIRAN; Database=ooc;UID=sa;Password=*****");
// Create Adapter
SqlDataAdapter dbAdapt = new SqlDataAdapter("SELECT * FROM tblFile1", dbConn);
// Create and initialize CommandBuilder
SqlCommandBuilder dbCB = new SqlCommandBuilder(dbAdapt);
// Open Connection
dbConn.Open();
// New DataSet
DataSet dbSet = new DataSet();
// Populate DataSet with data
dbAdapt.Fill(dbSet, "tblFile1");
// Get reference to our table
DataTable dbTable = dbSet.Tables["tblFile1"];
// Create new row
DataRow dbRow = dbTable.NewRow();
// Store data in the row
dbRow["FileName"] = strName;
dbRow["FileSize"] = Buffer.Length;
dbRow["ContentType"] = strType;
dbRow["FileData"] = Buffer;
// Add row back to table
dbTable.Rows.Add(dbRow);
// Update data source
dbAdapt.Update(dbSet,"tblFile1");
// Get newFileID
if( !dbRow.IsNull("FileID") )
nFileID = (int)dbRow["FileID"];
// Close connection
dbConn.Close();
// Return FileID
return nFileID;
}
plz any one give me an soln for the same
thanks in advance
View 5 Replies
View Related
Dec 26, 2001
Hi, I appreciate your help. I used to run a script to populate a table then send a message notification to a user via email. Lately, I am getting this error message. I have not changed any of the code in the procedure that run.
What could be wrong.
Thanks a gain for your help
Ali
Server: Msg 8152, Level 16, State 9, Line 12
String or binary data would be truncated.
View 1 Replies
View Related
May 21, 2002
Hi ...I am getting this error and the column that I am insertig into is of varchar type with max length of 4000.
Can I change this to nvarchar type of 8000 in the table design.
I wanted to be sure that it wont affect the data in any way.
Can anyone help me with this ....
View 2 Replies
View Related
Jul 20, 2005
Is there anything I can put in a stored procedure so instead of proc fallingover because of "String or binary data would be truncated" the offendingrecords are just truncated?Thanks for any help!
View 1 Replies
View Related
Jul 20, 2005
Hey everyone ..i have a website going .. .. ofcourse you use the Ws-FTP to upload thephotos to the page .. and i have to use SQL program to insert the filenames and values into the Database ..i have been doing this for the longest time .. ill show u anexample below ..Insert INTO PHoto (FOLDER, PIC_NAME, TAKEN_FROM, TAKEN_DATE, MONTH_YEAR,DISPLAY_FOLDER, MONTH_YEAR_ID) VALUES('PHOTO BLAH BLAH BLAH .. ..basically all the values .. the name and dates etc.been doin it for the longest time .. excute the line and it will give mean OK .. and my photo will be up on the website! ..i tried uploading some files today .. and i get this weird message![microsoft][ODBC SQL server Driver][Sql server]String or binary datawould be truncated.and now i can't put anythin into the database cause everytime i try toexcute and put those files up .. it gives me that error!can anyone help plz?--Posted via http://dbforums.com
View 4 Replies
View Related
Apr 16, 2008
String or binary data would be truncated.
The statement has been terminated.
I recieved this error messege after trying to do an insert on a memory table. Here's part of the stored proc:
I know im getting the error from the Bill_Customer_code, but dont know why! it has varchar 20, and when i run the query on its own, most of the values are about 5 characters. Any ideas?
Code Snippet
USE [RC_STAT]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[PROC_RPT_Breeder_Sales_Distributor]
AS
BEGIN
SET NOCOUNT ON;
Declare @ReportingTbl TABLE (
Source_Id int,
Territory_Code varchar(20),
Territory_Description varchar (30),
Sort_Id int,
Column_Text varchar(20),
Bill_Customer_Code varchar(20),
Customer_Name varchar (50),
Subbrand_Key int,
SubBrand_Description varchar (30),
Period_1 Decimal(18,0),
Period_2 Decimal(18,0),
Period_3 Decimal(18,0),
Period_4 Decimal(18,0),
Period_5 Decimal(18,0),
Period_6 Decimal(18,0),
Period_7 Decimal(18,0),
Period_8 Decimal(18,0),
Period_9 Decimal(18,0),
Period_10 Decimal(18,0),
Period_11 Decimal(18,0),
Period_12 Decimal(18,0),
Period_13 Decimal(18,0),
YTD Decimal (18,0),
Total_Amount decimal (18,0))
--Distributor Goals
INSERT INTO @ReportingTbl
(Source_Id,
Territory_Code,
Territory_Description,
Bill_Customer_Code,
Customer_Name,
Sort_Id,
Column_Text,
Subbrand_Key,
SubBrand_Description,
Period_1,
Period_2,
Period_3,
Period_4,
Period_5,
Period_6,
Period_7,
Period_8,
Period_9,
Period_10,
Period_11,
Period_12,
Period_13,
YTD,
Total_Amount)
SELECT
4 AS Source_Id,
Tbv_Customer.Breeder_Territory_Code,
RC_DWDB_INSTANCE_1.dbo.Qry_Sales_Group_Dimension.Territory_Name,
4 AS Sort_Id,
'Goal' AS Column_Text,
Bill_Customer_Code,
Tbv_Customer_1.Customer_Name,
999 AS Sub_Brand_ID,
'Distributor_Goal' AS Sub_Brand_Description,
SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 1 THEN cusSales.Customer_Sales_Summary_Amount ELSE 0 END) AS Period_1,
SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 2 THEN cusSales.Customer_Sales_Summary_Amount ELSE 0 END) AS Period_2,
SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 3 THEN cusSales.Customer_Sales_Summary_Amount ELSE 0 END) AS Period_3,
SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 4 THEN cusSales.Customer_Sales_Summary_Amount ELSE 0 END) AS Period_4,
SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 5 THEN cusSales.Customer_Sales_Summary_Amount ELSE 0 END) AS Period_5,
SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 6 THEN cusSales.Customer_Sales_Summary_Amount ELSE 0 END) AS Period_6,
SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 7 THEN cusSales.Customer_Sales_Summary_Amount ELSE 0 END) AS Period_7,
SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 8 THEN cusSales.Customer_Sales_Summary_Amount ELSE 0 END) AS Period_8,
SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 9 THEN cusSales.Customer_Sales_Summary_Amount ELSE 0 END) AS Period_9,
SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 10 THEN cusSales.Customer_Sales_Summary_Amount ELSE 0 END) AS Period_10,
SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 11 THEN cusSales.Customer_Sales_Summary_Amount ELSE 0 END) AS Period_11,
SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 12 THEN cusSales.Customer_Sales_Summary_Amount ELSE 0 END) AS Period_12,
SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 13 THEN cusSales.Customer_Sales_Summary_Amount ELSE 0 END) AS Period_13,
0 AS YTD,
SUM(cusSales.Customer_Sales_Summary_Amount) AS Total
FROM RC_DWDB_INSTANCE_1.dbo.Qry_Sales_Group_Dimension
INNER JOIN Tbv_Customer
ON RC_DWDB_INSTANCE_1.dbo.Qry_Sales_Group_Dimension.Territory_Code = dbo.Tbv_Customer.Breeder_Territory_Code
INNER JOIN RC_DWDB_INSTANCE_1.dbo.Tbl_Customer_Sales_Summary_Fiscal AS cusSales
ON Tbv_Customer.Customer_Code = cusSales.Customer_Code
INNER JOIN Tbv_Customer AS Tbv_Customer_1
ON cusSales.Bill_Customer_Code = Tbv_Customer_1.Customer_Code
WHERE (cusSales.Bill_Customer_Code NOT IN ('RNPROC', 'RNPROF','11825', '11990', '11971', '12013', '08105'))
AND (cusSales.Sub_Brand_Id <> 65) AND (cusSales.Report_Level_Id = 85)
AND (cusSales.Consolidated_Sales_Tables_Id = 32)
GROUP BY Tbv_Customer.Breeder_Territory_Code,
RC_DWDB_INSTANCE_1.dbo.Qry_Sales_Group_Dimension.Territory_Name,
cusSales.Customer_Sales_Summary_Year,
cusSales.Bill_Customer_Code,
Tbv_Customer_1.Customer_Name
View 3 Replies
View Related
Feb 13, 2008
Hi,
In MS SQL Server 2005, we currently have a stored procedure which creates a table where one of the fields Client ID is declared as a VARCHAR(8).
Then there is an INSERT INTO table statement but it returns the following error:
"String or binary data would be truncated."
We have checked the values to be inserted into the table and none of them exceed the limit.
The Client ID column currently contains values less than or equal to 8 characters in length and null values.
To debug, we have already done the following:
1. Insert the values seperately into the table
e.g. WHERE Client ID = 8
OR Client ID < 8
OR Client ID is null
There were no errors returned and all values were inserted into the table
2. (a) Selected all distinct values to be inserted and pasted it into Excel
(b) Then set the ANSI WARNINGS OFF - so it will select all distinct values and truncate the offending Client ID
(c) Pasted the result set returned in step (b) into Excel
(d) Compared the two columns to look for any differences and there were none!!
3. There are Client IDs like "0", "01", "11" - so thought that it may be something to do with SQL treating it like a binary....but we tried eliminating these values and performing the INSERT and the still get the error.
We are out of ideas and would greatly appreciate your help!!
Thanks!
View 5 Replies
View Related
Feb 17, 2008
use pubs
Insert Into stores
(stor_id, stor_name, stor_address, city, state, zip)
Values
('Test3', 'test store2', '1234', 'here', 'ny', '00319')
this query doesnt work and I get this error message
Msg 8152, Level 16, State 14, Line 1
String or binary data would be truncated.
The statement has been terminated.
while following one works fine , why.
Select * from stores where stor_id='test'
Insert INTO Stores
(stor_id, stor_name, city, state, zip)
Values
('TST2','Test store', 'here','ny', '00319')
View 4 Replies
View Related
Jan 13, 2008
I have created and when I attempt to perform the following INSERT statement I am receiving an error. Any suggestions?
Error
Msg 8152, Level 16, State 14, Line 1
String or binary data would be truncated.
The statement has been terminated.
INSERT INTO jobTitle (job_title,
ee01_Class,
job_description,
exempt_status)
VALUES ('Director of Finance & Accounting',
'Officials & Managers',
'Plans and directs the finance and accounting activities.',
'Exempt')
Table Code:
CREATE TABLE jobTitle (job_title VARCHAR(70) PRIMARY KEY,
ee01_Class VARCHAR(40) NOT NULL,
job_description VARCHAR(250) NOT NULL,
exempt_status VARCHAR(10) NOT NULL)
View 5 Replies
View Related
May 1, 2008
Hi all
I am passing a string to a variable. That variable is input to a function. When I execute that i am getting an error message
"String or binary data would be truncated."
When i pass a string with a length upto 12 char then it works fine but for more that 12 char it is throwing that error.
My all declared variables are of VARCHAR(MAX) type
Please anyone tell me how to solve this problem.
Thanks
Ashutosh
View 3 Replies
View Related
Aug 21, 2006
I need to insert multiple rows for input rows that meet certain conditions.
My input data is as follows.
ZIPCode, Plus 4, Range, City, State
What I need to happen is that if there is a value in the range column that is > 0 then I need to insert a row for every range item.
For instance say I have the following data.
54952, 1001, 10, Menasha, WI
What I need imported is :
54952, 1001, Menasha, WI
54952, 1002, Menasha, WI
54952, 1003, Menasha, WI
54952, 1004, Menasha, WI
54952, 1005, Menasha, WI
54952, 1006, Menasha, WI
54952, 1007, Menasha, WI
54952, 1008, Mensaha, WI
54952, 1009, Mensaha, WI
54952, 1010, Mensaha, WI
54952, 1011, Mensaha, WI
Any help in pointing me in the right direction would be great. Thanks for your help in advance.
View 2 Replies
View Related