JAM Posted November 14, 2003 Posted November 14, 2003 Hi everyone I'm trying to insert a new item using a stored procedure. In this case if the user leaves the category id textbox empty, then it sould be inserted as a null value. here is my code Dim catidparam As SqlParameter catidparam = New SqlParameter("@Category_id", SqlDbType.Int) catidparam.Direction = ParameterDirection.Input 'make null insertion Possible catidparam.Value = IIf(IsDBNull(txtcategoryid.Text), DBNull.Value, txtcategoryid.Text) myCmd.Parameters.Add(catidparam) But it doesn't work. I get error message saying "input string was not in a correct format" Please help. Quote
Moderators Robby Posted November 14, 2003 Moderators Posted November 14, 2003 In the SP list of params, set the default value to Null. @myVar varchar(10) Null, Quote Visit...Bassic Software
Moderators Robby Posted November 14, 2003 Moderators Posted November 14, 2003 I just noticed your code, instead do somthing like catidparam.Value = String.Empty (of course only if textbox is blank) Quote Visit...Bassic Software
JAM Posted November 15, 2003 Author Posted November 15, 2003 Dear Robby Thank you for replying. Niether approach solve the problem. Quote
Moderators Robby Posted November 15, 2003 Moderators Posted November 15, 2003 Actually if the textbox is blank you should skip this line myCmd.Parameters.Add(catidparam) and only change this in your SP @myVar varchar(10) Null Quote Visit...Bassic Software
CattleRustler Posted November 16, 2003 Posted November 16, 2003 is the column in the db set to accept null? Quote mod2software Home of the VB.NET Class Builder Utility - Demo and Full versions available now!
JAM Posted November 18, 2003 Author Posted November 18, 2003 Yes Cattle its been set toaccept null. Actually I have used Robby's approach by skiping and it work's. Thank you every one. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.