pruebens Posted December 17, 2002 Posted December 17, 2002 I have a form that has a bunch of textboxes and such bound to a SQL 2000 database. Now some of the columns in the database are supposed to have default values so that when a new record is added for instance, column 12 is automatically set to the word 'FALSE'. Now updating and the process of adding a new record works fine, however when I add a new record through my VB app the columns that are supposed to have default values of 'FALSE' are in turn set to null.......which of course craps out my application. And here is another twist, if I manually add a record using the SQL Admin console the columns get set with the correct default value. Now I know very little about SQL and our SQL admin knows even less than I do about VB .NET. SO imagine our pickle. Anyone have any ideas? Should I used the INSERT command (and if so could someone post the syntax) instead of the AddNew method? Thanks in advance. Maybe one day I won't be such a n00b. Quote
*Gurus* Derek Stone Posted December 17, 2002 *Gurus* Posted December 17, 2002 Use INSERT. AddNew() and binding is garbage. strSQL = "INSERT INTO myTable (Column1, Column2) VALUES ('pruebens', 'Derek Stone')" If you want to use default values for a field just don't specify the column or a value. Quote Posting Guidelines
pruebens Posted December 18, 2002 Author Posted December 18, 2002 Thanks Derek......you know I've only been programming for about 2 months now and only know what I've readin about 4 books. But I see your point as to why binding is garbage. It seems to be okay for simple tasks but try to put it in a complex proggoe and you get all sorts of wierd crap. Anyway can I do something like this?: INSERT INTO mytable (column1, column2) VALUE (Textbox1.text, Textbox2.text) Quote
Moderators Robby Posted December 18, 2002 Moderators Posted December 18, 2002 If you use variables or controls you need to seperate them with the & And notice that Derek and I used single quotes around the strings. 'pruebens' But don't use single quotes with numeric values strSql = "INSERT INTO mytable (column1, column2, column3) VALUE ('" & Textbox1.text & "','" & SomeStringVar & "'," & SomeNumericVar & ")" Quote Visit...Bassic Software
pruebens Posted December 18, 2002 Author Posted December 18, 2002 Cool thanks guys........I will give this a try. Quote
pruebens Posted December 18, 2002 Author Posted December 18, 2002 Okay here is my code that I created: Dim Conn As New SqlConnection("data source=<server>;initial catalog=<database>;persist security info=False;packet size=4096") Conn.Open() Dim cmd As SqlCommand = Conn.CreateCommand cmd.CommandText = "INSERT INTO <table> (ColumnName) VALUE ('" & Textbox1.Text & "')" cmd.ExecuteNonQuery() When I run this I get the following error: Line 1: Incorrect syntax near 'VALUE' Quote
*Experts* Volte Posted December 18, 2002 *Experts* Posted December 18, 2002 It has to be 'VALUES' with an 'S', I believe. Quote
pruebens Posted December 18, 2002 Author Posted December 18, 2002 That was it! MAN I'M SUCH A n00b!!! But it looks as though my problem is now solved as my default values were there!!!!! Derek you are right!!! BINDING IS GARBAGE!!!!! WOO HOO!!!! This virtual beer is for you! And now I will NOT forget how to do this! 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.