I have the following SQLite table.
CREATE TABLE "Ingredient_Detailed" (
"DETAILED_INGREDIENT_ID" TEXT,
"INGREDIENT_CODE" INTEGER NOT NULL,
"BRAND" TEXT NOT NULL,
"INGREDIENT_SOURCE" TEXT NOT NULL,
"UNIT_PRICE" REAL NOT NULL DEFAULT 0,
"AMOUNT_IN_UNIT" REAL NOT NULL DEFAULT 0,
"MINIMUM_PRICE_PER_UNIT" REAL NOT NULL DEFAULT 0,
"QUALITY" INTEGER NOT NULL DEFAULT 1,
"UNITS_AVAILABLE" INTEGER NOT NULL DEFAULT 0,
FOREIGN KEY("INGREDIENT_CODE") REFERENCES "Ingredient"("CODE"),
PRIMARY KEY("DETAILED_INGREDIENT_ID")
)
I have a C# application where I am trying to insert records into this table with the following method:
public int SaveDetailedIngredient(DetailedIngredient pDetailedIngredient)
{
try
{
using (var conn = new SQLiteConnection(GetConnectionString()))
{
var saveDetailedIngredientCommand = new SQLiteCommand("INSERT INTO INGREDIENT_DETAILED (DETAILED_INGREDIENT_ID, " +
"INGREDIENT_CODE, BRAND, INGREDIENT_SOURCE, UNIT_PRICE, AMOUNT_IN_UNIT, " +
"MINIMUM_PRICE_PER_UNIT, QUALITY, UNITS_AVAILABLE) " +
"VALUES ($pDetailedIngredientId, $pCode, $pBrand, $pSource, $pUnitPrice, $pAmountInUnit, $pPricePerUnit, $pQuality, $pUnitsAvailable)", conn);
pDetailedIngredient.DetailedIngredientCode = pDetailedIngredient.Code + "-" + pDetailedIngredient.Brand + "-" + pDetailedIngredient.IngredientSource;
saveDetailedIngredientCommand.Parameters.AddWithValue("pDetailedIngredientId", pDetailedIngredient.DetailedIngredientCode);
saveDetailedIngredientCommand.Parameters.AddWithValue("pCode", pDetailedIngredient.Code);
saveDetailedIngredientCommand.Parameters.AddWithValue("pBrand", pDetailedIngredient.Brand.Trim().ToUpper());
saveDetailedIngredientCommand.Parameters.AddWithValue("pSource", pDetailedIngredient.IngredientSource.Trim().ToUpper());
saveDetailedIngredientCommand.Parameters.AddWithValue("pUnitPrice,", pDetailedIngredient.UnitPrice);
saveDetailedIngredientCommand.Parameters.AddWithValue("pAmountInUnit", pDetailedIngredient.AmountInUnit);
saveDetailedIngredientCommand.Parameters.AddWithValue("pPricePerUnit", pDetailedIngredient.MinimumUnitPrice);
saveDetailedIngredientCommand.Parameters.AddWithValue("pQuality", pDetailedIngredient.Quality);
saveDetailedIngredientCommand.Parameters.AddWithValue("pUnitsAvailable", pDetailedIngredient.UnitsAvailable);
conn.Open();
return saveDetailedIngredientCommand.ExecuteNonQuery();
}
}
catch (SQLiteException sqlEx)
{
Console.WriteLine(sqlEx.Message);
Console.WriteLine(sqlEx.ErrorCode);
throw sqlEx;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
throw ex;
}
}
Despite indicating 9 fields and supplying 9 parameters, SQLite throws an exception saying "Unknown Error: Insufficient Parameters Supplied to Command".
I copy and pasted the name of the parameters to make sure there's no typo in them, yet it still throws the error.
I debugged the application during the method executing and the supplied pDetailedIngredient has all the necessary attribute values assigned, and I can see that each of the parameters in the command is being assigned correctly.
I have several other methods for inserting data into other tables, all follow the same structure, so I doubt that this is related to the way my method is written.
Am I missing something here? It doesn't feel like this is the right error.
I honestly wish I had a good answer as to “WHY” this is happening. I can only assume that the “AddWithValue” is doing something I am not aware of. However, after a some back and forth I would ask you to try this and see if it works for you as it did for me.
Is what I changed is by adding the parameters as shown below. This consistently worked with some testing and only failed as expected when the id was duplicated. Please let me know if this helps as I am with you in a sense that on the surface, your code looks good to me.
saveDetailedIngredientCommand.Parameters.Add("pDetailedIngredientId", DbType.String).Value = pDetailedIngredient.DetailedIngredientCode;
saveDetailedIngredientCommand.Parameters.Add("pCode", DbType.Int32).Value = pDetailedIngredient.Code;
saveDetailedIngredientCommand.Parameters.Add("pBrand", DbType.String).Value = pDetailedIngredient.Brand.Trim().ToUpper();
saveDetailedIngredientCommand.Parameters.Add("pSource", DbType.String).Value = pDetailedIngredient.IngredientSource.Trim().ToUpper();
saveDetailedIngredientCommand.Parameters.Add("pUnitPrice", DbType.Decimal).Value = pDetailedIngredient.UnitPrice;
saveDetailedIngredientCommand.Parameters.Add("pAmountInUnit", DbType.Decimal).Value = pDetailedIngredient.AmountInUnit;
saveDetailedIngredientCommand.Parameters.Add("pPricePerUnit", DbType.Decimal).Value = pDetailedIngredient.MinimumUnitPrice;
saveDetailedIngredientCommand.Parameters.Add("pQuality", DbType.Int32).Value = pDetailedIngredient.Quality;
saveDetailedIngredientCommand.Parameters.Add("pUnitsAvailable", DbType.Int32).Value = pDetailedIngredient.UnitsAvailable;
Let me know if this does not work for you and I will remove it.
Another potential cause of "Insufficient Parameters Supplied to Command" error
If you use an approach similar to the following for entering data into a SQLite DB programmatically:
create a class w/needed properties
instantiate class and populate the instance
save instance to DB
the class property name and DB column name must match (excluding case-sensitivity).
Example (I use NuGet Dapper so exact syntax may differ):
public class StartState
{
public string Phase { get; set; }
public string ArgText { get; set; }
public string startTime { get; set; }
}
// in winforms form.cs
private static void SaveStartState()
{
StartState model = new StartState();
{
model.Phase = Terms.Status;
model.ArgText = _tsarg;
model.startTime = starttTime4DB;
DBconnects.SaveState(model);
}
}
// in DBconnects.cs
public static void SaveState(StartState model)
{
using (var dbc = new SQLiteConnection(Connections.SQLiteDB()))
{
dbc.Execute($"insert into {DBtbl.State}(" +
"phase,argText,startTime)" +
" values(" +
"#phase,#argText,#startTime)"
, model);
}
}
// DB Definition
CREATE TABLE 'StartState' (
phase TEXT NOT NULL PRIMARY KEY,
argText TEXT,
startTime TEXT
);
Related
I'm trying to develop a simple custom connector to Qlik, where I Get the data from a source specific, load the data in the Qlik and extract the data according own query. However, I found some problems and question, that I describe bellow:
I pass the field, tableName and data for the connection like in the bellow codes, but when I click on "Load Data", the error "Object reference not defined as an instance of an object" is shown, how if the tables in the "QvAditiConnection.Init()" had not been defined. Bellow, the codes:
public QvAditiConectorConnection(QvxConnection connection)
{
try
{
_logApp = new LogApp();
_util = new ClsUtil();
_nomeTabela = " ";
_tipoConexao = " ";
_connectionString = " ";
_parameters = " ";
if (connection != null && connection.MParameters != null && connection.MParameters.Count > 0)
{
this.MParameters = connection.MParameters;
}
GetParametersFromConnection();
if (string.IsNullOrWhiteSpace(_parameters) == false)
{
_connectionStringParameters = _util.RecuperaParametrosConnectionString(_parameters);
_tipoConexao = _connectionStringParameters[0];
string connectionString = GetConnectionString();
if (TestarConexao(connectionString))
{
_connectionString = connectionString;
StartConnection();
}
else
{
_logApp.CriarLog("ERRO na conexão com o banco de dados.");
}
}
else
{
QvxLog.Log(QvxLogFacility.Audit, QvxLogSeverity.Error, "Init() Erro de conexão. Verifique os dados ou o servidor.");
}
Init();
}
catch (Exception ex)
{
_logApp = new LogApp();
if (string.IsNullOrWhiteSpace(ex.Message) == false)
{
QvxLog.Log(QvxLogFacility.Audit, QvxLogSeverity.Error, "Init() Erro: " + ex.Message);
_logApp.CriarLog("ERRO Constructor: " + ex.Message);
}
else
{
QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Init() Erro Desconhecido");
_logApp.CriarLog("ERRO não identificado");
}
}
}
public override void Init()
{
try
{
if (string.IsNullOrWhiteSpace(_parameters) == false)
{
QvxLog.SetLogLevels(true, true);
QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Init()");
List<QvxTable> tabelas = new List<QvxTable>();
DataTable schemaTables = _connectionPostGreSqlStaging.GetSchema("Tables");
foreach (DataRow row in schemaTables.Rows)
{
_nomeTabela = (string)row[2];
_dataTableStagingArea = new DataTable(_nomeTabela);
GetDataReader();
QvxTable dadosTable = new QvxTable();
dadosTable.TableName = _nomeTabela;
dadosTable.Fields = _qvxFields;
dadosTable.GetRows = GetDataRowsConnector;
tabelas.Add(dadosTable);
}
this.MTables = tabelas;
}
}
How can you see below, the connection is correct in this case, because the application gets and shows the tables and fields in the correct form:
Select Dialog
But, after I click in "Insert Script" and "Load Data", The error below is shown, how if the tables in the application has not been defined:
Error on click in load data button
The "ExtractQuery" is exact how bellow, and when I debug the code and use the "Add Watch" in parameter "qvxTables", I see that he's null and not contains Tables:
public IEnumerable<QvxDataRow> GetDataRowsConnector()
{
DataTable dadosTabela = _dataTableStagingArea;
foreach (var item in dadosTabela.Rows)
{
yield return MakeEntry(item as DataRow, FindTable(_nomeTabela, MTables));
}
}
public QvxDataRow MakeEntry(DataRow item, QvxTable table)
{
try
{
var row = new QvxDataRow();
for (int i = 0; i < _dataTableStagingArea.Columns.Count; i++)
{
var field = table.Fields.Where(a => a.FieldName == _dataTableStagingArea.Columns[i].ColumnName)
.Select(b => b).FirstOrDefault();
row[field] = item[field.FieldName].ToString();
}
return row;
}
catch (Exception ex)
{
throw new Exception(ex + "MakeEntry()");
}
}
In this case, when the Method "ExtractQuery" is called, the tables some times came, but the data don't came in the communication, similar to error 1. And in this case 2, when I debug step by step and arrive in the line "
dadosTable.GetRows = GetDataRowsConnector;" the debug don't enter in the"GetDataRowsConnector" or in the "MakeEntry", even when I insert breakpoints in the methods or press "F11" to use "Step Into".
How I show the preview data in select dialog(I use the QvxSdk in this case)? Even using the getPreview, I don't get the data and don't see example in the documentation. If do you have suggestions or examples for me, I appreciate if you share. And How I edit and select the fields to show in this window(How show or not Metadada, Selection Summary etc)? And how I insert a logo in the connector, like the connectors like "Oracle", "PostGreSql" etc?
select dialog with highlighted data area preview
When I click in the "Insert Script", I want to send a blank script to the editor, ao invés de send the script "Load [FIELD] SQL SELECT * FROM ...", and ao mesmo tempo get this script that the Qlik genereta automactilly in my backend, It's possible do this?
Wrong Script Editor Area
Correct Script Editor Area
Remember that I use the QvxSdk for this solution, based on the "Simple Example" provided for Qlik, but I'm open for suggestion for others APIs if is the case for answer my questions. I use too the .Net Framework 4.5 to develop the connector
Thank you in advance for your attention and help.
Thanks!
I have database connection setup with Entity Framework. I've created multiple stored procedures and one of them has an output parameter that I need in my application.
Procedure in c# :
public virtual ObjectResult<Nullable<System.Guid>> AjouterProfesseur(string prenom, string nom, ObjectParameter identity)
{
var prenomParameter = prenom != null ?
new ObjectParameter("prenom", prenom) :
new ObjectParameter("prenom", typeof(string));
var nomParameter = nom != null ?
new ObjectParameter("nom", nom) :
new ObjectParameter("nom", typeof(string));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<Nullable<System.Guid>>("AjouterProfesseur", prenomParameter, nomParameter, identity);
}
To retrieve the output parameter I use following (this is also where I have to put my breakpoint and step over it for it to work):
public static Guid AddProfesseur(string prenom, string nom)
{
using (ExamenProjetIntegrationEntities db = new ExamenProjetIntegrationEntities())
{
ObjectParameter objParam = new ObjectParameter("identity", typeof(Guid));
var resultToReturn = db.AjouterProfesseur(prenom, nom, objParam);
return Guid.Parse(objParam.Value.ToString());
}
}
Then I have a business layer who calls that method again :
public static Guid addProfesseur(string prenom, string nom)
{
try
{
var data = Data.AddProfesseur(prenom, nom);
return data;
}
catch (Exception e)
{
var sqlex = e.InnerException as SqlException;
if (sqlex != null)
{
switch (sqlex.Number)
{
default:
throw new Exception(sqlex.Number + " - " + sqlex.Message);
}
}
throw e;
}
}
And finally in my API controller I'm using following statement :
var idProfesseur = BL.addProfesseur(professeur.prenom, professeur.nom);
I call the method with ajax in my ASP.NET MVC view.
Does anyone has any idea why this is and how I can solve this issue?
EDIT :
Following link is exactly what I'm doing : Executing SQL Stored Procedure with Output Parameter from Entity Framework .But my problem is the fact that I need to step through it for it to work
Output parameters are not available until the return result has been read completely, or the underlying DbDataReader is closed.
See the Parameters section of ObjectContext.ExecuteFunction, and the second sentence of this section on DataReaders
You can force this by evaluating the result with LINQ.
public static Guid AddProfesseur(string prenom, string nom)
{
using (ExamenProjetIntegrationEntities db = new ExamenProjetIntegrationEntities())
{
ObjectParameter objParam = new ObjectParameter("identity", typeof(Guid));
var resultToReturn = db.AjouterProfesseur(prenom, nom, objParam).Count();
return Guid.Parse(objParam.Value.ToString());
}
}
You could also use .ToList(), .FirstOrDefault(), or whatever method you prefer to read the underlying result.
Using the underlying SqlParameter would require .Direction = ParameterDirection.Output. ObjectParameter doesn't have an equivalent setting. Instead I believe the parameter direction is configured in your model.
I have this unbelievably annoying issue with an Access db sitting on our server. It was working fine when yesterday it suddenly starting squatting out these
Invalid data type in criteria expression
So I tested on my machine - working fine
Uploaded that working code to the server - same error
Copied the db down to my machine - working fine
The only difference I can see between the data is that if I log the SQL query values to my error message I can see that a value for Document Date has a different format on my pc and on the server:
server
#documentDate : 2018-10-09 12:00:00 AM
local machine
#documentDate : 09/10/2018 12:00:00
All other values look exactly the same.
So is this an issue relating to locality/DateTime formats? If so, why can't Access just accept a DateTime value and store it appropriately, since that column is of data type Date/Time.
Would really appreciate some help on this it is driving my crazy.
Here is the code used to insert a record:
public int InsertAod(Aod aod)
{
if (CheckAod(aod) > 0)
{
Log.Message("This entry already exists");
return 1;
}
var cmd = new OleDbCommand(Constants.InsertAod);
cmd.Parameters.AddWithValue("#company", aod.ParentCollection.Company);
cmd.Parameters.AddWithValue("#businessUnit", aod.ParentCollection.BusinessUnit);
cmd.Parameters.AddWithValue("#sellerGln", aod.ParentCollection.SellerGln);
cmd.Parameters.AddWithValue("#messageId", aod.ParentCollection.MessageId);
cmd.Parameters.AddWithValue("#documentNo", aod.ParentCollection.DocumentNumber);
cmd.Parameters.AddWithValue("#documentDate", aod.ParentCollection.DocumentDate); // Data type of DocumentDate is DateTime
cmd.Parameters.AddWithValue("#region", aod.ParentCollection.Region);
cmd.Parameters.AddWithValue("#storeGln", aod.ParentCollection.StoreGln);
cmd.Parameters.AddWithValue("#storeCode", aod.ParentCollection.StoreCode);
cmd.Parameters.AddWithValue("#storeDescription", aod.ParentCollection.StoreDescription);
cmd.Parameters.AddWithValue("#lineItem", aod.LineItem);
cmd.Parameters.AddWithValue("#movementType", aod.MovementType);
cmd.Parameters.AddWithValue("#orderNo", aod.OrderNumber);
cmd.Parameters.AddWithValue("#reference", aod.ParentCollection.Reference);
cmd.Parameters.AddWithValue("#barcode", aod.Barcode);
cmd.Parameters.AddWithValue("#articleNo", aod.PnPArticleNumber);
cmd.Parameters.AddWithValue("#vendorCode", aod.VendorProductCode);
cmd.Parameters.AddWithValue("#articleDescription", aod.PnPArticleDescription);
cmd.Parameters.AddWithValue("#qty", aod.PnPQuantity);
try
{
//throw new Exception("how is this possible");
return ExecuteCommand(cmd, Execute.Insert);
}
catch (Exception e)
{
var data = cmd.Parameters.Count.ToString();
foreach (OleDbParameter parameter in cmd.Parameters)
{
data += $" {Environment.NewLine} {parameter.ParameterName} : {parameter.Value} {Environment.NewLine}";
}
Log.Error(e, $"Failed to insert AOD for {aod.OrderNumber} - {aod.LineItem}", data);
return 0;
}
}
Here is the code for CheckAod:
public int CheckAod(Aod aod)
{
var cmd = new OleDbCommand(Constants.CountAod);
cmd.Parameters.AddWithValue("#orderNo", aod.OrderNumber);
cmd.Parameters.AddWithValue("#messageId", aod.ParentCollection.MessageId);
cmd.Parameters.AddWithValue("#lineItem", aod.LineItem);
try
{
return ExecuteCommand(cmd, Execute.Count);
}
catch (Exception e)
{
Log.Error(e, "Failed to call CheckAod");
throw;
}
}
And the ExecuteCommand mentioned above:
private int ExecuteCommand(OleDbCommand cmd, Execute command)
{
var output = 0;
if (!(persistantConnection.State == ConnectionState.Open))
persistantConnection.Open();
cmd.Connection = persistantConnection;
using (cmd)
{
try
{
switch (command)
{
case Execute.Insert:
output = cmd.ExecuteNonQuery();
Log.Message("success");
break;
case Execute.Count:
output = (int)cmd.ExecuteScalar();
break;
}
}
catch (Exception e)
{
var data = cmd.Parameters.Count.ToString();
foreach (OleDbParameter parameter in cmd.Parameters)
{
data += $" {Environment.NewLine} {parameter.ParameterName} : {parameter.Value} {Environment.NewLine}";
}
Log.Error(e, "Failed to execute command", data);
throw;
}
return output;
}
}
This is what Constants.InsertAod looks like:
internal const string InsertAod =
#"INSERT INTO TAOD ([COMPANY], [BUSINESS UNIT], [SELLER GLN], [MESSAGE ID], [DOCUMENT NO],
[DOCUMENT DATE], [REGION], [STORE GLN], [STORE CODE], [STORE DESCRIPTION], [LINE ITEM],
[MOVEMENT TYPE], [ORDER NO], [REFERENCE], [BARCODE], [PNP ARTICLE NO],
[VENDOR PRODUCT CODE], [PNP ARTICLE DESCRIPTION], [PNP QTY])
VALUES (#company, #businessUnit, #sellerGln, #messageId, #documentNo, #documentDate, #region,
#storeGln, #storeCode, #storeDescription, #lineItem, #movementType, #orderNo, #reference,
#barcode, #articleNo, #vendorCode, #articleDescription, #qty)";
And I can confirm that the above values are in the same order as they appear in the db itself.
After a bunch of messing around I realised that the server was failing to convert the value PnPQuantity from string to number (the Access data type).
When I tried to do this explicitly I was getting this error
System.FormatException: Input string was not in a correct format.
Even though the string was in the form "18.000"
I changed my code to include a CultureInfo parameter:
decimal.Parse(aod.PnPQuantity, CultureInfo.InvariantCulture)
And it now works fine.
What I don't understand is why the machine suddenly can't handle converting a 18.000 to a number, when the localisation settings are configured to use . as a decimal seperator:
Also, since this was working fine a couple of days ago this means something must have changed on the server, but what could it possibly be?
I have a question regarding the code below, am trying to get the dropdown values from a generic query, passing the field and table name. I am getting the error Cannot assign to GetDropDownValues because it is a method group and not sure how to resolve? Can anyone shed some light? Thanks in advance...
public static DataTable GetDropDownValues(string pstrConString_Mfg, string pstrTableName, string pstrFieldName, string pstrField = "")
{
string strSQL;
DataTable dtRetTable;
try
{
strSQL = "SELECT DISTINCT " + pstrFieldName;
if (pstrField != "")
{
strSQL = strSQL + " , " + pstrField;
}
strSQL = strSQL + " FROM " + pstrTableName + " ORDER BY " + pstrFieldName;
dtRetTable = ExecuteDataTable(pstrConString_Mfg, CommandType.Text, strSQL);
if (dtRetTable != null)
{
if ((dtRetTable.Rows.Count == 0))
{
GetDropDownValues = new DataTable(); <--error
}
else
{
dtRetTable.BeginLoadData();
dtRetTable.Rows.InsertAt(dtRetTable.NewRow, 0);
dtRetTable.EndLoadData();
dtRetTable.AcceptChanges();
GetDropDownValues = dtRetTable;
}
}
else
{
GetDropDownValues = new DataTable();
}
}
catch (Exception ex)
{
throw ex;
}
}
--==================================================
Also am getting error on line ' dtRetTable.Rows.InsertAt(dtRetTable.NewRow, 0);'
cannot convert from 'method group' to 'DataRow'. I am assuming it is related to above error?
Where you wrote GetDropDownValues = dtRetTable; and GetDropDownValues = new DataTable(); looks like older Visual Basic (also Visual Basic for Applications, VBA) syntax for having a function return a value.
With C# (and C, C++, Java, JavaScript and a lot of others) you need to return a value and not assign it to the function name.
Do this instead:
return dtRetTable;
and
new DataTable();
Edit to address your other question...
For the error on the line dtRetTable.Rows.InsertAt(dtRetTable.NewRow, 0) doing as #Ed Plunkett suggested will fix this problem. As you said you are converting older code to work in C#, it will be easy to forget to add the trailing brackets () as required by C# but the error message you get of method group - Well, I've only ever seen it when I forget to put the brackets in, so it will be easier for you to understand what is going on.
And finally, do not catch Exceptions unless you intend to do something about the exception there and then. You should always catch the Exception in your Interface methods so you can show a nicer message to your users and prevent the app from crashing out.
Where you wrote throw ex;, it would be better to just write throw or if you are willing, remove the try/catch block entirely. When you throw ex you will destroy the correct StackTrace which is essential for debugging and figuring out what the problem is. There is lots of information (and a lot more in-depth) on this in StackOverflow as well as the rest of the Web.
Happy translating, and remember we love to help those who make an attempt to help themselves first.
The scenario is that I am trying to add a new site column, I need to update the schema definition.
the 2nd time the update executes it says the field was not found, but its there, I can even see it on site columns after the feature activating crashes
private void AddManagerField(SPWeb currentweb)
{
try
{
//Add new field to Site Columns
string managerFieldName = currentweb.Fields.Add(SponsoringCommon.Constants.FIELDS_SPONSORINGMANAGER_NAME, SPFieldType.User, false);
SPFieldUser managerField = currentweb.Fields.GetFieldByInternalName(managerFieldName) as SPFieldUser;
managerField.Group = SponsoringCommon.Constants.DEFAULT_TAXONOMY_TERMGROUP_NATIONALELOTERIJSPONSORING;
managerField.Update();
SPFieldUser managerField2 = currentweb.Fields.GetFieldByInternalName(managerFieldName) as SPFieldUser;
string schemaXmlWithResourceTokens = managerField2.SchemaXmlWithResourceTokens;
int startIndex = schemaXmlWithResourceTokens.IndexOf("\"", schemaXmlWithResourceTokens.IndexOf("DisplayName=\"")) + 1;
int endIndex = schemaXmlWithResourceTokens.IndexOf("\"", startIndex);
int substringLength = endIndex - startIndex;
string value = schemaXmlWithResourceTokens.Substring(startIndex, substringLength);
schemaXmlWithResourceTokens = schemaXmlWithResourceTokens.Replace(value, "$Resources:SPNLSponsoring,Field_SponsoringManager_Name");
managerField2.SchemaXml = schemaXmlWithResourceTokens;
managerField2.Update();
SPContentTypeId dossierCTID = new SPContentTypeId(SponsoringCommon.Constants.CONTENTTYPES_DOSSIER_ID);
SPContentType dossierCT = currentweb.ContentTypes[dossierCTID];
SPFieldLink managerFieldLink = new SPFieldLink(managerField2);
dossierCT.FieldLinks.Add(managerFieldLink);
dossierCT.Update(true);
}
catch (Exception ex)
{
Logger.LogError("error", "AddManagerField(SPWeb currentweb)", ex);
throw;
}
}
Have you checked the internal names are identical.
If you have access to the server try and get the GUID of the column and use that instead as this will guarantee you are looking for the correct field.
Is the field in the web you are passing in to this Method?
Sorry may seem simple but once i have sat down and been through my code (after debugging) i normally find i am being neglectful about chacking all the angles.
Hope this helps
Truez