Please refer to the question that started it all for me: C# SQLDataAdapter - Not inserting data into DB
I'm developing an archival system, well building on to it I should say. But my latest issue looks like this once I hit var rowsAffected = sqlAdapter.InsertCommand.ExecuteNonQuery();:
Additional information: The parameterized query '(@TableID int,@RowID int,@RowState tinyint,@UserID int,@XMLHisto' expects the parameter '@TableID', which was not supplied.
Now here's where it potentially gets a little tricky.. the tables that I'm trying to INSERT into, they don't have any primary or foreign keys associated to them. Not my design. I'm wondering if the above execute() call is having troubles with the INSERT because of this. I dont' have anything that I need to set as @@Identity because.. well I don't have anything like that available.
Thoughts?
Update:
As requested here's the query and the sql cmd..
string strInsertSQL = "INSERT INTO <tableName> (TableID, RowID, ModifyDate, RowState, UserID, XMLHistory, RowDescription) " +
"VALUES (@TableID, @RowID, GetDate(), @RowState, @UserID, @XMLHistory, @RowDescription); SET @NewID = @@Identity"; // SET statement needed?
sqlComm = new SqlCommand(strInsertSQL, sqlConnArchive);
sqlComm.Parameters.Add("@TableID", SqlDbType.Int, 4, "TableID"); // Not sure if this is needed since primary key doesn't exist?
// More params added here
Update:
On a whim I wanted to check to see what the InsertCommand.Parameters held. I took a look at @TableID value and it was Null.
sqlAdapter.Fill(myDS.myTable); // myTable.count = 7k+
var x = sqlAdapter.InsertCommand.Parameters; // x-@tableID value = null
var rowsAffected = sqlAdapter.InsertCommand.ExecuteNonQuery();
I have a feeling that's why I'm seeing this error. Anyone have any thoughts on how I can resolve this?