Results 1 to 8 of 8

Thread: SQL problem in updating table

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2007
    Posts
    133

    SQL problem in updating table

    I am trying to save some records to a sql table. I am trying to save a string for the Market segment. But i get a problem, "Cannot set column 'Market Seg'. The value violates the MaxLength limit of this column."

    The datatype set for that column is text, and the value trying to be stored in it is "Magazine - B2B". Im new to SQL, can someone point out what is going on?

    Code:
    If saverow = 0 Then
                saverow2 = MainDBDataSet.Assesments.NewRow()
                saverow2.Item("Customer") = CustomerName
                saverow2.Item("Cust ID") = CustomerNum
                saverow2.Item("Title") = title
                saverow2.Item("Title ID") = title
                saverow2.Item("Market Seg") = marketSeg
                MainDBDataSet.Tables("assesments").Rows.Add(saverow2)
                AssesmentsTableAdapter.Update(MainDBDataSet.Assesments)

  2. #2
    Fanatic Member Clanguage's Avatar
    Join Date
    Jan 2008
    Location
    North Carolina
    Posts
    659

    Re: SQL problem in updating table

    It is very bad practice to name table fields with space in them. If you cannot avoid it then at least surround them with brackets although I do not see any valid cases where you would need to use spaces. You will encounter all kinds of unwanted behavior when you use spaces.
    Code:
    If saverow = 0 Then
                saverow2 = MainDBDataSet.Assesments.NewRow()
                saverow2.Item("Customer") = CustomerName
                saverow2.Item("[Cust ID]") = CustomerNum
                saverow2.Item("Title") = title
                saverow2.Item("[Title ID]") = title
                saverow2.Item("[Market Seg]") = marketSeg
                MainDBDataSet.Tables("assesments").Rows.Add(saverow2)
                AssesmentsTableAdapter.Update(MainDBDataSet.Assesments)
    CLanguage;
    IF Post = HelpFull Then
    RateMe
    Else
    Say("Shut UP")
    End If
    DotNet rocks
    VB 6, VB.Net 2003, 2005, 2008, 2010, SQL 2005, WM 5.0,ahem ?OpenRoad?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2007
    Posts
    133

    Re: SQL problem in updating table

    Thanks, that seemed to solve the problem. However the values are not staying in the database, when the program ends the SQL database is not updated. The method im using worked for Access does it not update a SQL database? When the program starts over the values in the DB are gone.

  4. #4
    Fanatic Member Clanguage's Avatar
    Join Date
    Jan 2008
    Location
    North Carolina
    Posts
    659

    Re: SQL problem in updating table

    You need to show us the code if you want to know why the data does not persist.
    CLanguage;
    IF Post = HelpFull Then
    RateMe
    Else
    Say("Shut UP")
    End If
    DotNet rocks
    VB 6, VB.Net 2003, 2005, 2008, 2010, SQL 2005, WM 5.0,ahem ?OpenRoad?

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2007
    Posts
    133

    Re: SQL problem in updating table

    Code:
    saverow2 = MainDBDataSet.Assesments.NewRow()
                saverow2.Item("Customer") = CustomerName
                saverow2.Item("CustID") = CustomerNum
                saverow2.Item("Title") = title
                saverow2.Item("TitleID") = title
                saverow2.Item("MarketSeg") = marketSeg
                saverow2.Item("Frequency") = frequency
                saverow2.Item("Reason") = reasonForAssess
                saverow2.Item("term") = termofquote
                saverow2.Item("prepress") = prepressTotal
                saverow2.Item("press") = CoverTotal + BF1Total + BF2Total + BF3Total + BF4Total + coatingtotal
                saverow2.Item("bind") = bindTotal
                saverow2.Item("ancillary") = 1
                saverow2.Item("paper") = PaperTotPrice
                saverow2.Item("prepressBM") = prepressTotalBM
                saverow2.Item("pressBM") = pressbm
                saverow2.Item("bindBM") = bindTotalBM
                saverow2.Item("ancillaryBM") = 1
                saverow2.Item("paperBM") = PaperTotPrice
    
                MainDBDataSet.Tables("assesments").Rows.Add(saverow2)
                AssesmentsTableAdapter.Update(MainDBDataSet.Assesments)
                MsgBox("Assesment has been saved to database")

  6. #6
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: SQL problem in updating table

    Are you using SQL Exress or SQL Server (the full version)? You might have set the application to overwrite the database file on application start.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  7. #7
    Fanatic Member Clanguage's Avatar
    Join Date
    Jan 2008
    Location
    North Carolina
    Posts
    659

    Re: SQL problem in updating table

    Hi Stogie03,
    I am glad to see that you corrected the names to not include spaces. Great move.
    Do you have this code in a loop and an error control block? Do you get any error? Can you step into the code and see what your update is doing?
    CLanguage;
    IF Post = HelpFull Then
    RateMe
    Else
    Say("Shut UP")
    End If
    DotNet rocks
    VB 6, VB.Net 2003, 2005, 2008, 2010, SQL 2005, WM 5.0,ahem ?OpenRoad?

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Oct 2007
    Posts
    133

    Re: SQL problem in updating table

    Its the full version i believe, developer edition.

    How would i have set the application to overwrite the DB on startup. This is the only place the code appears. In visual studio the database appears as all null's when i view the table.

    This method works fine on my Access DB's, im just trying to switch things over to SQL.

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