|
-
Mar 27th, 2008, 10:50 AM
#1
Thread Starter
Addicted Member
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)
-
Mar 27th, 2008, 11:09 AM
#2
Fanatic Member
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?
-
Mar 27th, 2008, 11:21 AM
#3
Thread Starter
Addicted Member
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.
-
Mar 27th, 2008, 11:23 AM
#4
Fanatic Member
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?
-
Mar 27th, 2008, 11:38 AM
#5
Thread Starter
Addicted Member
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")
-
Mar 27th, 2008, 11:45 AM
#6
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
-
Mar 27th, 2008, 11:46 AM
#7
Fanatic Member
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?
-
Mar 27th, 2008, 11:58 AM
#8
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|