Reputation: 63
i have textbox1 in form as "NOTE" when i type text in textbox1 and press insert button it's work but when i get that text again from DB to textbox1 and try to remove the text (to remove the NOTE from DB) and the cursor is in the textbox1 .. and press insert button again i get this error :
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.dll
Additional information: SqlCommand.Prepare method requires all variable length parameters to have an explicitly set non-zero Size.
how i can use if statement to cheek if textbox1 IsNullOrEmpty or IsNullOrWhiteSpace i have tried them both not working ..
Upvotes: 1
Views: 479
Reputation: 3386
SqlCommand.Prepare method requires all variable length parameters to have an explicitly set non-zero Size.
this means that when you are pressing the button for the next time the NOTE.Length = 0 and p11.Size is set to zero, which is not acceptable and giving rise to the issue.
This being said you can try something like this:
if(NOTE.Length > 0)
p11.Size = NOTE.Length;
else
p11.Size = 1;//<-non-zero Size in case the NOTE length happens to be zero.
//also same check for NOTE itself as well if you wish. check whether it is NULL or not and set p11 Value accordingly
Hope this helps.
Upvotes: 2