Anyone else run into this?

pruebens

Well-known member
Joined
Nov 21, 2002
Messages
71
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 wont be such a n00b.
 
Use INSERT. AddNew() and binding is garbage.

Code:
strSQL = "INSERT INTO myTable (Column1, Column2) VALUES (pruebens, Derek Stone)"

If you want to use default values for a field just dont specify the column or a value.
 
Thanks Derek......you know Ive only been programming for about 2 months now and only know what Ive 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?:

Code:
INSERT INTO mytable (column1, column2) VALUE (Textbox1.text, Textbox2.text)
 
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 dont use single quotes with numeric values
Code:
strSql = "INSERT INTO mytable (column1, column2, column3) VALUE (" & Textbox1.text & "," & SomeStringVar & "," & SomeNumericVar & ")"
 
Okay here is my code that I created:


Code:
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
 
That was it! MAN IM 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!
 
Back
Top