Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I'm getting 'ORA-01745: invalid host/bind variable name' error while adding data into the oracle database

When I try to add data into the database, I get this error. Certain information I obtain, gets added to the other tables I have created. This problem occurs only regarding one table.

Here's my code :

public class NewOtherCompanyMapper
{
    OtherCompany om;
    private Database db;
    private DbCommand cmd;
    private DbConnection con;

    public void AddNDADetails(string id)
    {
        try
        {
            con = db.CreateConnection();
            con.Open();

            string query = string.Format("INSERT INTO NDAInformation (NDAID,RegNumber,DateCreate,RefName,ReqServ,ServDetails) VALUES (:ndaID,:regnumber,TO_DATE(:date,'DDMMYYYY'),:refname,:regserv,:servdetails)");
            cmd = db.GetSqlStringCommand(query);
            cmd = con.CreateCommand();
            cmd.CommandText = query;
            db.ExecuteNonQuery(cmd);

            db.AddInParameter(cmd, "ndaID", DbType.String, id);
            db.AddInParameter(cmd, "regnumber", DbType.String, om.RegNumber);
            db.AddInParameter(cmd, "date", DbType.Date, om.Date);
            db.AddInParameter(cmd, "refname", DbType.String, om.ComRef);
            db.AddInParameter(cmd, "regserv", DbType.String, om.ComService);
            db.AddInParameter(cmd, "servdetails", DbType.String, string.Join(",", om.ReqServiceDetails));
        }

        catch (Exception ex)
        {
            throw ex;
        } 
    }
}
like image 375
Problem Child Avatar asked Aug 31 '26 22:08

Problem Child


1 Answers

ORA-01745: invalid host/bind variable name

Cause: A colon in a bind variable or INTO specification was followed by an inappropriate name, perhaps a reserved word.

Action: Change the variable name and retry the operation.

=============================================================

Eg::.

Dim nCount As Integer

sSQL = "SELECT COUNT(*) FROM USERS WHERE USER_ID = :UID"

OracleConnection conn = new OracleConnection(ConfigurationSettings.AppSettings("connString"));
conn.Open();
OracleCommand cmd = new OracleCommand(sSQL, conn);

cmd.CommandType = CommandType.Text;

cmd.Parameters.Add("UID", OracleType.VarChar).Value = txtUserID.Text;

nCount = cmd.ExecuteScalar();
like image 195
Gehan Fernando Avatar answered Sep 03 '26 12:09

Gehan Fernando