I'm using FBCommand
to insert data into a single table in ASP.NET and using the <defaultConnectionFactory type="FirebirdSql.Data.EntityFramework6.FbConnectionFactory, EntityFramework.Firebird" />
In my insert method, I create the following command:
INSERT INTO PERSONEN ( NACHNAME, VORNAME, GEBURTSDATUM, STRASSE, PLZ, ORT, LAND, TELEFONNUMMER, EMAIL)
VALUES (:Nachname, :Vorname, :Geburtsdatum, :Strasse, :PLZ, :Ort, :Land, :Telefonnummer, :Email)
RETURNING ID into :Returnvalue;
(I'm using :
here instead of @
, because when I used @
for the parameters, it gave me an unknown token "@" error)
When it tries to run the command as "ExecuteNonQuery", I get the SQL error -206 Column Unknown NACHNAME
I'm convinced theres no typo here: https://gyazo.com/6366c37e86a2073a157b38bd732e3ecd
I have no clue what the error could be. I even followed the FAQ from the Firebird homepage (where strangely they add parameters with @
, but that's another story)
Here's the full code for the method:
private int InsertOrUpdateRecord(bool ForceNew)
{
string command = "";
if(ForceNew)
{
command = "INSERT INTO PERSONEN ( NACHNAME, VORNAME, GEBURTSDATUM, STRASSE, PLZ, ORT, LAND, TELEFONNUMMER, EMAIL)" +
" VALUES (:Nachname, :Vorname, :Geburtsdatum, :Strasse, :PLZ, :Ort, :Land, :Telefonnummer, :Email)";
}
else
{
command = "UPDATE OR INSERT INTO PERSONEN (ID, NACHNAME, VORNAME, GEBURTSDATUM, STRASSE, PLZ, ORT, LAND, TELEFONNUMMER, EMAIL)" +
" VALUES (:ID, :Nachname, :Vorname, :Geburtsdatum, :Strasse, :PLZ, :Ort, :Land, :Telefonnummer, :Email)";
}
command += " RETURNING ID into :Returnvalue;";
FbCommand cmd = new FbCommand(command);
cmd.CommandType = CommandType.Text;
//ID ist ein Sonderfall, diese hat keine Textbox Controls so wie die Spalten in der folgenden For Schleife, da sie readonly ist.
cmd.Parameters.AddWithValue(":" + gdvPersonDetailedData.Columns[0].HeaderText, gdvPersonDetailedData.Rows[0].Cells[0].Text);//@ID
for (int i = 1; i < gdvPersonDetailedData.Columns.Count; i++)//Übrige Parameter
{
cmd.Parameters.AddWithValue(":" + gdvPersonDetailedData.Columns[i].HeaderText, ((TextBox)gdvPersonDetailedData.Rows[0].Cells[i].Controls[0]).Text);
}
cmd.Parameters.Add(":Returnvalue", FbDbType.Integer).Direction = ParameterDirection.Output;//Für den Returnwert
cmd.Connection = c;
if(cmd.Connection.State != ConnectionState.Open)
{
cmd.Connection.Open();
}
cmd.ExecuteNonQuery();
return (int)cmd.Parameters[":Returnvalue"].Value;
}