exception adding query to SqlCommand (C# Net6.0)
15:36 03 Sep 2026

I have the following code:

conn.Open();
SqlCommand addEntry = new SqlCommand(
    "INSERT INTO D7TQUEUE "
    + "(Batch_id, Mnemonic, BaseTable, Value) "
    + "VALUES "
    + "(@Batch_id, @Mnemonic, @BaseTabe, @Value) ", conn);

addEntry.Parameters.Add("@Batch_id", SqlDbType.Int);
addEntry.Parameters.Add("@BaseTable", SqlDbType.VarChar, 5);
addEntry.Parameters.Add("@Value", SqlDbType.VarChar, 7);
addEntry.Prepare();

I get a system.null reference exception adding the first parameter [@Batch_id]

I have done this many times in .net framework (with oracle database) but this fairly new territory for me using net6 and sqlClient

c# parameters sqlclient