>From reading your response I'm thinking that your passing the value of the textbox straight to your update SQL before doing any input validation on it. This is NOT a good way to do things as it can allow for malicious attacks against your code. What you should do is validate your inputs before sending them to your tableadapter update command. At this point check to see if the text box is empty. If it is, pass DBNull.Value as the variable value to the tableadapter update command.
What you're trying to do is not as simple as 'just setting the textbox field to null and then saving the updated data.' DBNull is not a string which is what a textbox requires for input, which is why you can't just set the textbox field to null. On Dec 23, 8:53 am, Snoopy33 <[email protected]> wrote: > On Dec 23, 9:38 am, Cerebrus <[email protected]> wrote: > > > I suggest you re-read what Cody wrote. > > Ok, fair enough, and i apologize in advance for my lack of > understanding. But that is of course why i'm seeking help. > > > > > When posting it back to the SQL server set the field to DBNull.Value > > I'm assuming that the > Me.OrdertblTableAdapter.Update(Me.DataSet1.Ordertbl) > is where i need to set the field to dbnull.value since that is where > the updated data is being committed to the DB. > > > > > You can't put that inside a textbox's .text property though, which > > So do i set the field to "" ? so that it's blank? > > > > > means in your database access function that does the write you'll > > > > likely have to check for a blank value and then set it to DBNull.Value > > How would I check for a blank value? something like > > if me.textbox.text = "" then or maybe if me.textbox.text = nothing ? > > and if so, how do you set the value to dbnull without setting the > textbox to some form of null? > > > > > just before executing the query back to the server. > > When creating the FK, the field is simply set by double clicking on a > datagridview entry and populating the textbox with the appropriate > field value in that gridview. If i doubleclick on the bottom > unpopulated (null) field in the datagridview, it writes null value to > the field and saves perfect. Forgive me if i'm making inaccurate > assumptions, but isn't it just setting the textbox field to null and > then saving the updated data?
