Using visual studio 2012 express to create a web api that connects to a sql database and searches for a term, and returns values. When I run the code, the sql string works. I can copy the string and load it into a query in SQL server 2014 and expected results are returned. However, when I run the code here my sql string - on the return data - all my values are null.
Does anyone perhaps have any suggestions
Thank you
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
namespace WebAPi
{
public class TableBusinessTerm : TableGenericBase<stBusinessTerm>
{
private string TableName = "[MetadataRepository].[dbo].[QrySocialGraphMobile]";
public override void CreateTable()
{
throw new NotImplementedException();
}
public stBusinessTerm GetBusinessTerm(string termName)
{
string sql = "Select * From " + TableName + " Where BusinessTerm = '" + termName + "'";
var data = new stBusinessTerm();
bool result = GetRecord(ref data, sql);
return data;
}
protected override void DatabaseRow_Get(DataRow dr, ref stBusinessTerm data)
{
DatabaseUtilities.DataRow_Get(dr, "BusinessTerm", ref data.BusinessTerm);
DatabaseUtilities.DataRow_Get(dr, "BusinessTermLongDesc", ref data.BusinessTermLongDesc);
DatabaseUtilities.DataRow_Get(dr, "DomainCatID", ref data.DomainCatID);
DatabaseUtilities.DataRow_Get(dr, "SystemName", ref data.SystemName);
DatabaseUtilities.DataRow_Get(dr, "DataSteward", ref data.DataSteward);
DatabaseUtilities.DataRow_Get(dr, "DomainCatName", ref data.DomainCatName);
DatabaseUtilities.DataRow_Get(dr, "GoldenSource", ref data.GoldenSource);
DatabaseUtilities.DataRow_Get(dr, "GTS_table", ref data.GTS_table);
DatabaseUtilities.DataRow_Get(dr, "TableOwnerName", ref data.TableOwnerName);
DatabaseUtilities.DataRow_Get(dr, "Synonym", ref data.Synonym);
}
protected override void DatabaseRow_Get(long autoIncrementedID, ref stBusinessTerm data)
{
throw new NotImplementedException();
}
protected override void DatabaseRow_Set(ref DataRow dr, stBusinessTerm data)
{
throw new NotImplementedException();
}
}
}
bool result = GetRecord(ref data, sql); return datatermName) to create SQL - that's really really dangerous - you should look at parameters. However, the more relevant thing here is that you seem to be using some custom code that you aren't showing us. We can't tell what the problem is if we can't see whatGetRecorddoes or whatDatabaseRow_Getdoes. Right now, it would just throwNotImplementedExceptions. What even isstBusinessTerm? What is the relationship betweenGetRecordandDatabaseRow_Get? because right now: nothing calls that, andGetRecorddoesn't existTERMNAMEis being passed from a Web page. This then creates thestring sqlwhich is why I have concatenated the inputs. I have never used sqlDataAdapter, so thought it would be easier to create the sql string and then pass the values to the data rows - clearly this is not the case. Was hoping it was something silly like I had left of a comma, or something, but now see its more complex than that. Thanks for the advise thus far