Trying to build a Dynamic SQL string in my c# code. Not sure where I'm going wrong with it.
private void Save_Item_Drop_Data()
{
string uri = string.Empty;
string strUpdate = string.Empty;
WBGUpdateValue Update = new WBGUpdateValue();
Update.Email = Game_Data._User_Account.Email;
try
{
foreach (Base_Item item in Game_Data._Item_Drop)
{
//Recipe
if (item.Name.Contains("Recipe"))
{
if (Update_Recipe(item.Name))
{
uri = Game_Data._EndPoint + "api/WhiteboxGaming/Post_UnlockRecipe";
strUpdate = strUpdate + "UPDATE Skill_Gemology SET " + item.Name + "= 1 WHERE Email = ''" + Update.Email + "'' ";
_txtGameMessage.text = item.Name + " Unlocked";
}
}
//Rune
else if (item.Name.Contains("Rune") || item.Name == "Polished_Ancient_Stone" || item.Name == "Ancient_Stone")
{
uri = Game_Data._EndPoint + "api/WhiteboxGaming/Post_SaveItemdrop";
strUpdate = strUpdate + "UPDATE Inventory_Runes SET " + item.Name + "=" + item.Name + " + " + item.Count.ToString() + " WHERE Email = ''" + Update.Email + "'' ";
_txtGameMessage.text = "Found Rune";
}
Debug.Log(Update);
}
}
catch (Exception ex)
{
Debug.Log(ex);
}
if (Game_Data._Item_Drop.Count > 0)
{
Update.Value_1 = strUpdate;
StartCoroutine(booleanwebrequest(uri, Update));
}
Game_Data._Item_Drop = new List<Base_Item>();
}
The string builds this:
UPDATE Inventory_Runes SET Polished_Ancient_Stone=Polished_Ancient_Stone + 1 WHERE Email = ''help.whiteboxgaming@gmail.com''
When I run it via SQL I get an error:
Msg 911, Level 16, State 4, Line 74
Database 'UPDATE Inventory_Runes SET Polished_Ancient_Stone=Polished_Ancient_Stone + 1 WHERE Email = 'help' does not exist. Make sure that the name is entered correctly.
I understand what its telling me but I'm not sure how to fix the Email part in my c# code.
Update: now I'm really confused. I have the dynamic SQL correct but it still fails.
Update:
//Rune
else if (item.Name.Contains("Rune") || item.Name == "Polished_Ancient_Stone" || item.Name == "Ancient_Stone")
{
uri = Game_Data._EndPoint + "api/WhiteboxGaming/Post_SaveItemdrop";
strUpdate = strUpdate + "UPDATE Inventory_Runes SET [" + item.Name + "] = [" + item.Name + "] + " + item.Count.ToString() + " WHERE Email = ''' + @Email + '''";
_txtGameMessage.text = "Found Rune";
}
Outputs:
'UPDATE Inventory_Runes SET [Polished_Ancient_Stone] = [Polished_Ancient_Stone] + 4 WHERE Email = ''' + @Email + '''UPDATE Inventory_Runes SET [Rune_sa] = [Rune_sa] + 1 WHERE Email = ''' + @Email + '''UPDATE Inventory_Runes SET [Polished_Ancient_Stone] = [Polished_Ancient_Stone] + 1 WHERE Email = ''' + @Email + '''UPDATE Inventory_Runes SET [Ancient_Stone] = [Ancient_Stone] + 2 WHERE Email = ''' + @Email + '''UPDATE Inventory_Runes SET [Ancient_Stone] = [Ancient_Stone] + 1 WHERE Email = ''' + @Email + ''''
When I tear it apart it looks like this:
UPDATE Inventory_Runes SET [Polished_Ancient_Stone] = [Polished_Ancient_Stone] + 4 WHERE Email = 'help.whiteboxgaming@gmail.com'
UPDATE Inventory_Runes SET [Rune_sa] = [Rune_sa] + 1 WHERE Email = 'help.whiteboxgaming@gmail.com'
UPDATE Inventory_Runes SET [Polished_Ancient_Stone] = [Polished_Ancient_Stone] + 1 WHERE Email = 'help.whiteboxgaming@gmail.com'
UPDATE Inventory_Runes SET [Ancient_Stone] = [Ancient_Stone] + 2 WHERE Email = 'help.whiteboxgaming@gmail.com'
UPDATE Inventory_Runes SET [Ancient_Stone] = [Ancient_Stone] + 1 WHERE Email = 'help.whiteboxgaming@gmail.com'