Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted

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) 

  • Moderators
Posted

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 & ")"

Visit...Bassic Software
Posted

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'

Posted

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!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...