We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Updating Database

Howcome I'm getting an error when I'm trying to save an empty string into the database? VB6 allows me to do that without any problems. I'm getting an error if the txtQty.text is empty. It won't let me save it coz it's empty. How do I get around it? .... row.item("Qty") = txtQty.text .... dataadapter.update(dsList, "List")

5 Replies

CB Clay Burch Syncfusion Team June 12, 2002 04:27 AM UTC

A couple of things to check. Is Qty a numeric value in your database? Maybe that is why it would not accept an empty STRING. Try using a zero instead. Also, there are several properties floating around that are named AllowDBNull. For example, there is one in the datacolumn: MyTable.Columns("Qty").AllowDBNull = True Make sure all these are set properly. Another thing to try would be to conditionally set row("Qty") = DBNull.Value if the string is empty.


AD Administrator Syncfusion Team June 12, 2002 08:38 AM UTC

I tried it but it only allows me to update one empty field.. both my field's datatypes are "text" 'this works.. if txtQty.text = "" then row.item("Qty") = DbNull.Value row.item("Price") = txtPrice.text row.item("Product") = txtProduct.text **** 'this doesn't work elseif txtQty.text = "" AND txtPrice.text = "" .. row.item("Qty") = DbNull.Value row.item("Price") = DbNull.Value row.item("Product") = txtProduct.text When two fields are empty then I'm getting an error in the dataadapter.update! I've also added the myTable.Columns("Qty").AllowDBNull = true inside my procedure but this is not doing anything.. i think.. pls. help! I've been stuck on this for almost a week already. :(


CB Clay Burch Syncfusion Team June 13, 2002 05:32 AM UTC

You might try switching the order of your if clauses. Your elseif block will never be executed as the first alternative (your orignal if) will be true whenever your 2nd alternative is true. You also probably want to have an elseif for the price being "" too.


AD Administrator Syncfusion Team June 13, 2002 09:09 PM UTC

I tried that but no luck! I don't think it's my if statements. b/c i checked it and it's going inside the elseif but it's just not executing it. it just won't allow me to insert two fields that are null. is there any other way of getting around it? coz i already checked the properties of the fields and the allowDbNull is set to true. so what wrong?? :( > You might try switching the order of your if clauses. Your elseif block will never be executed as the first alternative (your orignal if) will be true whenever your 2nd alternative is true. You also probably want to have an elseif for the price being "" too


CB Clay Burch Syncfusion Team June 14, 2002 12:46 PM UTC

Try putting a Try-Catch around this problem code to see if any exceptions are being thrown in this code. That might help point to the problem.

Loader.
Up arrow icon