通过我的Web应用程序将字符串保存在数据库中时,字符串字符被删除 [英] String character getting deleted when I save it in the database through my web app

查看:71
本文介绍了通过我的Web应用程序将字符串保存在数据库中时,字符串字符被删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码



I have this code

con.ConnectionString = "Data Source=aaaa;Initial Catalog=aaa;User ID=aaa;Password=aaa";
                con.Open();
                SqlCommand cmd = new SqlCommand("exec doc_record @PO_NUMBER, @Path,@Time_Saved, @Scanned_BY", con);
                // cmd.Parameters.AddWithValue("@PO_NUMBER", Label4.Text);
                cmd.Parameters.Add("@PO_NUMBER", SqlDbType.VarChar, 250).Value = Label4.Text;
                cmd.Parameters.Add("@Path", SqlDbType.NVarChar).Value = NewFileName;
                cmd.Parameters.Add("@Time_Saved", SqlDbType.NVarChar).Value = "";
                cmd.Parameters.Add("@Scanned_BY", SqlDbType.NVarChar).Value = Environment.UserName;
                cmd.ExecuteNonQuery();
                con.Close();
                confirm();





我尝试过:



有一个文本框可以保存采购订单编号。因此,当我在文本框645-5263038-O9-SMIPLX中输入此PO编号并按保存。字母X每次都被修剪,并保存为645-5263038-O9-SMIPL,但如果我在数据库中手动输入,则现在出现问题。在字段长度设置为Varchar(20)之前,但现在我已经超过它到Varchar(100)但仍然存在问题。



What I have tried:

There is a textbox to save the PO Number. So when i enter this PO number in the text box "645-5263038-O9-SMIPLX" and press save. The letter 'X' gets trimmed everytime and it is saved as "645-5263038-O9-SMIPL" but if i enter it manually in the database then there is now problem. Before the length of the field was set to Varchar(20) but now i have exceeded it to Varchar(100) but there still is a problem.

推荐答案

是的,存储过程中的参数大小@PO_NUMBER可能是错误的大小; 它需要增加至少文本框的大小或传入的数据的最大大小。如果列不够大,那么你会得到一个像:字符串或二进制数据将被截断。语句已被终止。
Yes, the parameter size in your stored procedure @PO_NUMBER is probably the wrong size; it will need to be increased to at least the size of the textbox or the maximum size of the data which you are passing in. If the column was not big enough, then you'd get an exception like: "String or binary data would be truncated. The statement has been terminated."


这篇关于通过我的Web应用程序将字符串保存在数据库中时,字符串字符被删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆