The question is simple.
I have data type NYHARA (20) .. So when I try to enter a data in this column, for example 22 characters, then instead of just throwing an exception, the last 2 Ignore the letter!
Is this normal? ..and how to secure the database from such an issue?
PS: Of course I use verification control and server verification, but how do I keep the database safe, there is any kind of advanced barrier, just by specifying the length of the column, it throws an exception and Does not accept the entry date ??
Edit Well, I am using this code, and BTW I have tried to put a bigger data than just the length of the column from SQL Management Studio and it actually lets you The message displays were just describing! The problem is between these two rows. SQL Server Never gets more than 20 characters. NET is transancing. I do not remember the documentation for SQLParameter, a Google search was fast. Now if you should have length of SILPRAM 40, then automatically the string will be stripped for 40 characters on the net .. and no error (But you can lose data and do not know it).
try {try (SqlConnection conn = New SqlConnection (ConnStr)) {string command = "SET NOCOUNT ON , INSERT [country] (country name, isvizible) value (@ name, @IsVisible); "; (SqlCommand comm = new SqlCommand (Command, conn)) using {comm.Parameters.Add ("@Name", System.Data.SqlDbType.NVarChar, 20); Comm.parameters ["@Name"]. Value = name; Comm.parameters.Add ("@ isvisible", System.Data.SqlDbType.Bit); com. Parameter ["iswizible"]. Value = invisible; Conn.Open (); Comm.ExecuteNonQuery (); Return "Successfully Added" + Name + "In Countries."; }}} Hold (SqlException SqlEx) {string ErrorMessage = ""; (Int i = 0; I & lt; SqlEx.Errors.Count; i ++) {Error message + = SqlEx.Errors [i]. Number + ":" + SqlEx.Errors [i]. Message + "\ n"; } Return error message; }
com Parameter.Add ("@Name", System.DataSQLDType.NVarChar, 20); Comm.parameters ["@Name"]. Value = name;
Comments
Post a Comment