This is an odd question, and I hope I framed it correctly. I am using the Visual Studio DataSet designer to create SQL table adapters to link my project to a SQL server. The connection string is via an ODBC entry.
All tables have default queries, like update and insert. In the dataset.Designer.cs file, these commands are auto-generated. Here's one example:
this._adapter.DeleteCommand = new global::System.Data.Odbc.OdbcCommand();
this._adapter.DeleteCommand.Connection = this.Connection;
this._adapter.DeleteCommand.CommandText = "DELETE FROM [pftestbench].[dbo].[TestData_TestGroupInstrument] WHERE (([TestGroup" +
"RecordNumber] = ?) AND ([InstrumentSerial] = ?))";
this._adapter.DeleteCommand.CommandType = global::System.Data.CommandType.Text;
this._adapter.DeleteCommand.Parameters.Add(new global::System.Data.Odbc.OdbcParameter("Original_TestGroupRecordNumber", global::System.Data.Odbc.OdbcType.BigInt, 0, global::System.Data.ParameterDirection.Input, ((byte)(0)), ((byte)(0)), "TestGroupRecordNumber", global::System.Data.DataRowVersion.Original, false, null));
this._adapter.DeleteCommand.Parameters.Add(new global::System.Data.Odbc.OdbcParameter("Original_InstrumentSerial", global::System.Data.Odbc.OdbcType.NVarChar, 0, global::System.Data.ParameterDirection.Input, ((byte)(0)), ((byte)(0)), "InstrumentSerial", global::System.Data.DataRowVersion.Original, false, null));
I am interested in the CommandText line:
this._adapter.DeleteCommand.CommandText = "DELETE FROM [pftestbench].[dbo].[TestData_TestGroupInstrument] WHERE (([TestGroup" +
"RecordNumber] = ?) AND ([InstrumentSerial] = ?))";
You can see how this depends on the database name, and how it is undesirable in case I change database names. Now, all but one of the tables specify the database name. The one table that does not, has a CommandText line like this:
this._adapter.DeleteCommand.CommandText = @"DELETE FROM [TestData_Instrument] WHERE (([Serial] = ?) AND ((? = 1 AND [Model] IS NULL) OR ([Model] = ?)) AND ((? = 1 AND [CalibrationDue] IS NULL) OR ([CalibrationDue] = ?)) AND ((? = 1 AND [Trace] IS NULL) OR ([Trace] = ?)) AND ((? = 1 AND [Manufacturer] IS NULL) OR ([Manufacturer] = ?)))";
The last one is what I would want ideally, because it is Database Name independent. This is why I used an ODBC to begin with, but clearly I am not doing something right.
My question is, how can I ensure that all these entries will be database name independent?