Interview Question in SQL Server Performance Tuning


 

Interview Question :: What would cause this error in my cSharp statement


It doesn't like "Category." If I remove all the code to handle the category column, it works fine. I'm working in Visual Studio 2005, and I'm stumped...???

MY CODE:

OleDbConnection myConn;
myConn = new OleDbConnection("Provider=Advantage OLE DB Provider;Data Source=\\\\server123\\ m \\dst \\plx_data\\ planfaxsystem.add; User Id=XXXXXXXXXX; Password=XXXXXXXXXX;");

myConn.Open();

string morningStar = "MorningStar";

string sql2 = String.Format("INSERT INTO PERFORMANCE_TABLE(SecurityName, Ticker, Cusip, Category) VALUES ('{0}', '{1}', '{2}', '{3}')", fundName, ticker, cusip, category);

OleDbCommand cmd = new OleDbCommand(sql2, myConn);
cmd.ExecuteNonQuery(); // ** CRASHES HERE **
if (myConn != null && myConn.State == ConnectionState.Open)
{
myConn.Close();
}



ERROR MESSAGE:
Error 7200: AQE Error: State = 01004; NativeError = 2102; [Extended Systems][Advantage SQL Engine]Data truncated INSERT INTO SYSTEM_PERFORMANCE (SecurityName, Ticker, Cusip, Category) VALUES ('Newton Balanced', 'STASX', '001285400', 'Moderate Allocation')
Answers to "What would cause this error in my cSharp statement"
RE: What would cause this error in my cSharp statement?

check the types on the columns you are inserting into. It seems the insert is failing because it was cause some of your data to be truncated. (say its a varchar(50) and you are inserting 55 characters)
 
Vote for this answer ::  
RE: What would cause this error in my cSharp statement?

Is Cusip supposed to be an integer or a varchar? With the single-quotation marks around 001285400 in the SQL statement, I believe the sql server will interpret that as characters, instead of a number.
 
Vote for this answer ::  
RE: What would cause this error in my cSharp statement?

Have you tried renaming the column Category to cat or cate or something because the error as per you r question is on the CATEGORY column.
 
Vote for this answer ::  
Update Alert Setting