Results 1 to 3 of 3

Thread: inserting "null" value into a database from vb6 front end.

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    5
    hi,
    i am facing an unusual problem when I am trying to insert a "null" value into SQL Server database.suppose I have a table named X and in that tables i have three columns a,b,c.suppose i say a is varchar datatype,b is numeric and it allows nulls,c is numeric
    now as b allows nulls,i want to insert a null "null" into column b.One way of coming around this problem is in the front end using a querydef i use the insert statement as follows.insert into x(a,c)values(& a &,& c &).ie i ommit the column that i want to enter a null.but i feel this to be a crude solution.i want to use an insert statement in which i use all values and if i am not including any thing in the front end ie not sending any value then a "null" should be entered into the database.
    My second problem is i manually inserted a null<null>(ie i left a particular numeric column empty while entering a record into a particular table with the help of Sql Server enterprise manager.now when i am trying to retrieve this record i am getting an error.
    i can come around this problem by mentioning on error resume next on the top.Can any one give me a better solution than this.

  2. #2
    Fanatic Member Ianpbaker's Avatar
    Join Date
    Mar 2000
    Location
    Hastings
    Posts
    696
    Hello pavan_kumard

    When you create the SQL string for the insert string try using an inline if statement. Eg.
    Code:
    strSQl = "INSERT into x(a,b,c)values(" & text1 & "," & iif(text2 = "",Null,text2) & "," & text3 & ")"
    This might sort ou your problem

    hope this helps

    Ian
    Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!

  3. #3
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Lightbulb

    You can work around your second problem by including some code which checks for null values in the fields of the tables. You can either make use of VB statements like

    if len(trim(<fieldname>.value)) = 0 then
    'this condition is true if the field is null




    Perhaps you may need to adapt the code to work with numeric and text data types.

    Hope it helps.
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width