Results 1 to 5 of 5

Thread: Generic SQL and .NET help [RESOLVED]

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2002
    Posts
    24

    Generic SQL and .NET help [RESOLVED]

    Heyas!

    Did the usual searching...couldn't come up with anything...

    I'm new to .NET, but have a good grasp of VB6.

    Anyway, I'm sure I have a configuration error, but I can't figure out where. Seems like .NET is much more strict about having your program setup the exact way it wants...

    Ok, I have a simple Windows app that is trying to read and write to a SQL Server on the company network.

    I'm using an OleDb dataadapter and connection. (Never could get the SQL data components working...). I don't get any errors when I create the components through the wizard, everything looks good.

    I can also read the SQL Server table and dump it all in the dataadapter/dataset without issue.

    As far as writing, I can't update any of the fields in a given row if that row has null values in it. Even if the field I'm dealing with doesn't have a null, as long as there is a null somewhere in the row it throws an error. I set the data adapter to update on error anyway (not caring about the other fields) but of course it doesn't do anything but move on.

    In any case, I'm sure this is a configuration error with my data adapter or some other property I need to set. I've looked everywhere, including my numerous books, but can't seem to hit on the right search string to find my answer.

    Thanks for any help!
    Last edited by Dador; May 28th, 2004 at 01:14 PM.

  2. #2
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    If I could see your code, I could probably help

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Check the table definition. Does the columns allow NULL values? If the col is defined with a NOT NULL clause it means that it cannot accept NULL and the whole row will be rejected.

    This is what it sounds like to me.

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Apr 2002
    Posts
    24
    Ok, here's some code I knocked up for testing...

    Also, the table does allow for nulls, as some fields can and need to be empty during different times.

    VB Code:
    1. 'clear the dataset
    2.         dsTape.Clear()
    3.  
    4.         'dim sql variable for clean code, set strVirtualTable also for
    5.         'clean code - not really necessary but reminds me it is a virtual table
    6.         Dim strSQL As String
    7.         strVirtualTable = "Tape"
    8.  
    9.         'grab the whole data row of the user inputed tape number
    10.         strSQL = "SELECT * FROM dbo.UtilityTapeData " & _
    11.                 "WHERE [Tape_Number] = '" & intTapeNumber & "'"
    12.  
    13.         'setup the dataset and get the sql statement from above
    14.         daTape.FillSchema(dsTape, SchemaType.Source, strVirtualTable)
    15.         daTape.SelectCommand.CommandText = strSQL
    16.         daTape.Fill(dsTape, strVirtualTable)
    17.  
    18.  
    19.         'test area, just try to throw some info into the comments field
    20.         Dim objRow As DataRow
    21.         objRow = dsTape.Tables(strVirtualTable).Rows.Find(intTapeNumber)
    22.         objRow.Item("Comments") = "4444"
    23.         daTape.Update(dsTape, strVirtualTable)

    Thanks for taking a look fellas!
    Last edited by Dador; May 28th, 2004 at 10:18 AM.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2002
    Posts
    24
    Ok fellas, figured it out...sorta.

    There was some problem with the dataset. Apparently, I generated the dataset back when I had the database setup to NOT allow nulls. Therefore, the dataset grabbed that mapping apparently. So, after I changed the database to allow nulls, the dataset didn't update itself.

    I had to search around in the .xsd file to find tha attribute for the dataset that showed it wouldn't accept a null. Unfortunately, I couldn't change it from there.

    So, I deleted it and generated a new dataset. All is well.

    Thanks for the help everyone.

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