I'm transferring information from one Access DB to another using C#. Using the following code generates an error but by putting the query in Access using the same values, I get no error. Can anyone see what is going on?
string sqlInfaction = "INSERT INTO AquiredInfractions" +
"(AgentID, DateID, InfractionID, STime, Durration, Exception) " +
"SELECT " +
"#ID AS AgentID, (SELECT D.DateID FROM DateCodes AS D WHERE D.DateValue = #DT) AS DateID, " +
"I.InfractionID, #ST AS STime, #DR AS Durration, #E AS Exception " +
"FROM " +
"InfractionTypes AS I " +
"INNER JOIN " +
"Groupings AS G " +
"ON I.GroupingID = G.GroupingID " +
"WHERE " +
"G.GroupingTitle = #NAME " +
"AND " +
"I.MinDur <= #DR1 AND I.MaxDur >= #DR2;";
OleDbCommand InfCmd = null;
Then the setup:
string conString = #"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\New.Employee\Documents\UserMan2.accdb";
conn = new OleDbConnection(conString);
InfCmd = new OleDbCommand(sqlInfaction, conn);
InfCmd.Parameters.Add("#ID", OleDbType.Integer);
InfCmd.Parameters.Add("#DT", OleDbType.Date);
InfCmd.Parameters.Add("#ST", OleDbType.SmallInt);
InfCmd.Parameters.Add("#DR", OleDbType.SmallInt);
InfCmd.Parameters.Add("#E", OleDbType.Boolean);
InfCmd.Parameters.Add("#NAME", OleDbType.VarWChar);
InfCmd.Parameters.Add("#DR1", OleDbType.SmallInt);
InfCmd.Parameters.Add("#DR2", OleDbType.SmallInt);
And in the transfer function:
InfCmd.Parameters["#ID"].Value = inf.AgentID;
InfCmd.Parameters["#DT"].Value = inf.date;
InfCmd.Parameters["#ST"].Value = inf.startTime;
InfCmd.Parameters["#DR"].Value = inf.durration;
InfCmd.Parameters["#E"].Value = inf.exception;
InfCmd.Parameters["#NAME"].Value = inf.infract;
InfCmd.Parameters["#DR1"].Value = inf.durration;
InfCmd.Parameters["#DR2"].Value = inf.durration;
InfCmd.ExecuteNonQuery();
In testing, I stepped through the running code, using the values that are put into the above parameters to test the query in Access.
The Value of sqlInfaction via quickwatch:
sqlInfaction "INSERT INTO AquiredInfractions(AgentID, DateID, InfractionID, STime, Durration, Exception)
SELECT #ID AS AgentID, (SELECT D.DateID FROM DateCodes AS D WHERE D.DateValue = #DT) AS DateID,
I.InfractionID, #ST AS STime, #DR AS Durration, #E AS Exception FROM InfractionTypes AS I
INNER JOIN Groupings AS G ON I.GroupingID = G.GroupingID WHERE G.GroupingTitle = #NAME
AND I.MinDur <= #DR1 AND I.MaxDur >= #DR2;" string
The exception gives the following:
Message: Syntax error in INSERT INTO statement.
Error Code: -2147217900
If there is something specific from the exception thrown, let me know but that is the entire message.
After playing around, I found the answer to be missing [] around Exception. The correct query reads:
string sqlInfaction = "INSERT INTO AquiredInfractions" +
"(AgentID, DateID, InfractionID, STime, Durration, [Exception]) " +
"SELECT " +
"#ID AS AgentID, (SELECT D.DateID FROM DateCodes AS D WHERE D.DateValue = #DT) AS DateID, " +
"I.InfractionID, #ST AS STime, #DR AS Durration, #E AS [Exception] " +
"FROM " +
"InfractionTypes AS I " +
"INNER JOIN " +
"Groupings AS G " +
"ON I.GroupingID = G.GroupingID " +
"WHERE " +
"G.GroupingTitle = #NAME " +
"AND " +
"I.MinDur <= #DR1 AND I.MaxDur >= #DR2;";
Related
I am having an issue with the query below:
SELECT
tT.RequestID,
TStatus,
TLead,
RequestDate,
tG.Category,
tETM.RAgency,
ECost,
tTT.TType
FROM
tT AS tT
INNER JOIN
tTMain AS tETM ON tT.RequestID = tETM.RequestID
INNER JOIN
tTType AS tTT ON tETM.AMod = tTT.TypeID
INNER JOIN
tGup AS tG ON tT.Category = tG.CategoryID
WHERE
tT.active = 1
AND (ApproxDate BETWEEN '09/30/2016' AND '09/30/2017')
AND tT.Category = 3
I am currently getting an error:
Conversion failed when converting date and/or time from character string.
The way I populate the above query in code:
string theQ = "SELECT " +
"tT.RequestID, " +
"TStatus, " +
"TLead, " +
"RequestDate, " +
"tG.Category, " +
"tETM.RAgency, " +
"ECost, " +
"tTT.TType " +
"FROM " +
"tT AS tT " +
"INNER JOIN " +
"tTMain AS tETM " +
"ON " +
"tT.RequestID = tETM.RequestID " +
"INNER JOIN " +
"tTType AS tTT " +
"ON " +
"tETM.AMod = tTT.TypeID " +
"INNER JOIN " +
"tGup AS tG " +
"ON " +
"tT.Category = tG.CategoryID " +
"WHERE " +
"tT.active = #val1 " +
"AND " +
"(ApproxDate BETWEEN #val2 AND #val3) " +
"AND " +
"tT.Category = #val4"
//Split up the between check. (it looks like this: BETWEEN 'xx/xx/xxxx' AND 'xx/xx/xxxx')
string[] betweenSplit = Regex.Split(Session["between"].ToString(), " AND ");
SqlDataAdapter da = new SqlDataAdapter();
DataSet _ds1 = new DataSet();
command = new SqlCommand(theQ, con);
command.Parameters.AddWithValue(1, "1");
command.Parameters.AddWithValue(2, betweenSplit[0].Replace(" BETWEEN ", ""));
command.Parameters.AddWithValue(3, betweenSplit[1]);
command.Parameters.AddWithValue(4, Session["UCat"].ToString());
da = new SqlDataAdapter(command);
da.Fill(_ds1, dbName);
da.Dispose();
closeAllConnections();
command.Parameters.Clear();
The error occurs on the line:
da.Fill(_ds1, "tripData");
What would I be doing incorrectly because the same query above works just fine when running it in Server Management Studio?
I suggest to avoid implicit conversion of date to/from string.
In your case it could be (for example):
CONVERT (datetime, '09/30/2016',101)
You should pass Datetime parameter to SQL like that
var yourFromDate = DateTime.Now;
SqlParameter fromDate = new SqlParameter("#val2", SqlDbType.DateTime) {Value = yourFromDate};
command.Parameters.Add(fromDate);
At the moment I am trying to query a broken database in c#. The recently introduced error is that when data is input in a particular way, a value in a column is defaulted to 0, which is problematic for me, as I have no control over what the user does or what the dba does.
To get around this, I have found another path to the data I need to output to the user. Problem is there is I have the requirement from my supervisor to support the old method in the event of the column coming up as a non-zero number.
I am trying to do this with either a case or an if command, but I not that great with sql, so I am not 100% sure where I am going wrong or how to go about it properly/efficiently. These are the commands in their current states:
SqlCommand caseCmd = new SqlCommand(
"SELECT H.CREATED, H.STATUSCODE, H.DETAILS, H.YEAR, H.MONTH, H.DAY, H.ITEMTEXT, TC.DOCLE, TC.ICPC, TC.ICD10, TERMCODE =" +
" CASE H.ITEMCODE WHEN 0" +
" THEN TN.TERMID" +
" ELSE H.ITEMCODE END" +
" FROM " + _databaseName + ".dbo.PASTHISTORY H" +
" INNER JOIN " + _drugDatabaseName + ".dbo.TERMNAMES TN ON TN.TERMNAME = H.ITEMTEXT" +
" INNER JOIN " + _drugDatabaseName + ".dbo.TERMCODES TC ON TC.TERMID = TERMCODE" +
" INNER JOIN " + _drugDatabaseName + ".dbo.CONDITIONS C ON C.TERMID = TERMCODE" +
" WHERE H.INTERNALID = #patientid" +
" AND H.RECORDSTATUS = 1" +
" AND ((H.CREATED >= #mindate) OR ((H.UPDATED IS NOT NULL) AND (H.UPDATED >= #mindate)))" +
" AND TC.RECORDSTATUS = 1",
Connection);
caseCmd.Parameters.AddWithValue("#patientid", int.Parse(patientId));
caseCmd.Parameters.AddWithValue("#mindate", minEnteredDate);
// Current error:
// When using 'TC.TERMID = TERMCODE', I get the error 'The conversion of the varchar value
// "3951000119103 " overflowed an int column'.
// This is alleviated by using either TN.TERMID OR H.ITEMCODE
SqlCommand ifCmd = new SqlCommand(
"IF (H.ITEMCODE = 0)" +
" SELECT H.CREATED, H.STATUSCODE, H.DETAILS, H.YEAR, H.MONTH, H.DAY, H.ITEMTEXT, TC.DOCLE, TC.ICPC, TC.ICD10, TN.TERMID" +
" FROM " + _databaseName + ".dbo.PASTHISTORY H" +
" INNER JOIN " + _drugDatabaseName + ".dbo.TERMNAMES TN ON TN.TERMNAME = H.ITEMTEXT" +
" INNER JOIN " + _drugDatabaseName + ".dbo.TERMCODES TC ON TC.TERMID = TN.TERMID" +
" INNER JOIN " + _drugDatabaseName + ".dbo.CONDITIONS C ON C.TERMID = TN.TERMID" +
" WHERE H.INTERNALID = #patientid" +
" AND H.RECORDSTATUS = 1" +
" AND ((H.CREATED >= #mindate) OR ((H.UPDATED IS NOT NULL) AND (H.UPDATED >= #mindate)))" +
" AND TC.RECORDSTATUS = 1" +
" ELSE IF (H.ITEMCODE <> 0)" +
" SELECT H.CREATED, H.STATUSCODE, H.DETAILS, H.YEAR, H.MONTH, H.DAY, H.ITEMTEXT, H.ITEMCODE, TC.DOCLE, TC.ICPC, TC.ICD10" +
" FROM " + _databaseName + ".dbo.PASTHISTORY H" +
" INNER JOIN " + _drugDatabaseName + ".dbo.TERMCODES TC ON TC.TERMID = H.ITEMCODE" +
" INNER JOIN " + _drugDatabaseName + ".dbo.CONDITIONS C ON C.TERMID = H.ITEMCODE" +
" WHERE H.INTERNALID = #patientid" +
" AND H.RECORDSTATUS = 1" +
" AND ((H.CREATED >= #mindate) OR ((H.UPDATED IS NOT NULL) AND (H.UPDATED >= #mindate)))" +
" AND TC.RECORDSTATUS = 1",
Connection);
ifCmd.Parameters.AddWithValue("#patientid", int.Parse(patientId));
ifCmd.Parameters.AddWithValue("#mindate", minEnteredDate);
// Current error:
// Getting two lines both saying 'The multi-part identifier "H.ITEMCODE" could not be bound.'
// I trust this is because of the IF and ELSE IF statements.
// Starting to think IF isn't the answer for me.
// Use either
SqlDataReader rdr = caseCmd.ExecuteReader();
// or
// SqlDataReader rdr = ifCmd.ExecuteReader();
Is this even remotely feasible or should I look into just making two sql commands for both alternatives and search through them both?
For clarity I took SQL out of C# string and used CTE. Basically, you can first patch the data and then use it for the lookups:
WITH PatchedHistory AS (
SELECT
H.CREATED, H.STATUSCODE, H.DETAILS, H.YEAR, H.MONTH, H.DAY, H.ITEMTEXT
, COALESCE(TN.TERMID, H.ITEMCODE) AS ITEMCODE --< TERMID with ITEMCODE fall-back
FROM _databaseName.dbo.PASTHISTORY H
LEFT JOIN _drugDatabaseName.dbo.TERMNAMES TN
ON H.ITEMCODE = 0 --< Lookup only if ITEMCODE is 0
AND TN.TERMNAME = H.ITEMTEXT
WHERE H.INTERNALID = #patientid --< Apply most of the filtering here
AND H.RECORDSTATUS = 1
AND ((H.CREATED >= #mindate) --< Suspicious condition
OR ((H.UPDATED IS NOT NULL) AND (H.UPDATED >= #mindate))
)
)
SELECT H.CREATED, H.STATUSCODE, H.DETAILS, H.YEAR, H.MONTH, H.DAY, H.ITEMTEXT, H.ITEMCODE
, TC.DOCLE, TC.ICPC, TC.ICD10 --< Add the rest of the data
FROM PatchedHistory H
INNER JOIN _drugDatabaseName.dbo.TERMCODES TC
ON TC.TERMID = H.ITEMCODE --< Join on the "patched" ITEMCODE
INNER JOIN _drugDatabaseName.dbo.CONDITIONS C
ON C.TERMID = H.ITEMCODE --< Join on the "patched" ITEMCODE
WHERE TC.RECORDSTATUS = 1
Also this condition looks suspicious:
AND ((H.CREATED >= #mindate)
OR ((H.UPDATED IS NOT NULL) AND (H.UPDATED >= #mindate))
)
technically it is equivalent to just
AND ((H.CREATED >= #mindate) OR (H.UPDATED >= #mindate))
It looks like the intention was
AND COALESCE(H.UPDATED, H.CREATED) >= #mindate
I'm tring to add the Insert, Update and Delete commands to a MySqlDataAdapter which has the data added to it with the command:
//iec211.4521studenti
string lv_sObsTable = "`" + mv_sDatabase + "`.`" + mv_sGroup + "observatii`";
string lv_sStudTable = "`" + mv_sDatabase + "`.`" + mv_sGroup + "studenti'";
string lv_sObservatiiCommand = "SELECT o.idObservatie, o.idStudent, s.nume, o.observatie, o.lastUpdate FROM " + lv_sObsTable + " o INNER JOIN " + lv_sStudTable + " s USING (idStudent) ORDER BY s.nume ASC";
mv_dtAdapterObservatii = new MySqlDataAdapter(lv_sObservatiiCommand, mv_sqlConnection);
mv_dtAdapterObservatii.Fill(mv_dsTables, lv_sCurrentTable);
I've serched for an answer and I've found two possible solutions for UPDATE, but both of them give me an error:
string lv_sObsTB = "`" + mv_sDatabase + "`.`" + mv_sGroup + "observatii`";
string lv_sStudTB = "`" + mv_sDatabase + "`.`" + mv_sGroup + "studenti`";
//VERSION 1
string lv_sCommand = "UPDATE o SET s.idStudent=#idStudent, o.observatie=#observatie FROM " + lv_sObsTB + " AS o INNER JOIN " + lv_sStudTB + " s ON o.idStudent=s.idStudent ";
MySqlCommand lv_sqlCommand = new MySqlCommand(lv_sCommand);
lv_sqlCommand.Parameters.Add("#idStudent", MySqlDbType.Int16, 10, "idStudent");
lv_sqlCommand.Parameters.Add("#observatie", MySqlDbType.VarChar, 255, "observatie");
mv_dtAdapterObservatii.UpdateCommand = lv_sqlCommand;
//VERSION 2
string lv_sCommand = "UPDATE " + lv_sObsTB + " SET " + "idStudent=#" + lv_sStudTB + ".idStudent, observatie=#observatie WHERE idObservatie=#idObservatie AND " + lv_sObsTB + ".idStudent IN (SELECT " + lv_sStudTB + ".idStudent FROM " + lv_sStudTB + ")";
MySqlCommand lv_sqlCommand = new MySqlCommand(lv_sCommand);
lv_sqlCommand.Parameters.Add("#" + lv_sStudTB + ".idStudent", MySqlDbType.Int16, 10, "idStudent");
lv_sqlCommand.Parameters.Add("#observatie", MySqlDbType.VarChar, 255, "observatie");
lv_sqlCommand.Parameters.Add("#idObservatie", MySqlDbType.Int16, 10, "idObservatie");
mv_dtAdapterObservatii.UpdateCommand = lv_sqlCommand;
The error message for the first version is : "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM iec211.4521observatii ASS o INNER JOIN iec211.4521studenti s ON o.id' at line 1"
The error message for the second version is:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.4521studenti'.idStudenti, observatie='test' WHERE idObservatie=1 ANDiec211.' at line 1"
I don't know how to use the MySQL commands in combination with MySqlCommand and MySqlDataAdapter.
Until now I've used the following command to obtain data for my table:
string lv_sObservatiiCommand = "SELECT * FROM `" + mv_sDatabase + "`.`" + mv_sGroup + "observatii` ORDER BY idStudent ASC";
mv_dtAdapterObservatii = new MySqlDataAdapter(lv_sObservatiiCommand, mv_sqlConnection);
mv_dtAdapterObservatii.Fill(mv_dsTables, lv_sCurrentTable);
In combination with MySqlCommandBuilder to get the update command and the parameters that needed to be setted:
lv_sqlCommandBuilder = new MySqlCommandBuilder(mv_dtAdapterObservatii);
mv_dtAdapterObservatii.UpdateCommand = lv_sqlCommandBuilder.GetUpdateCommand();
Can someone please explain to me how to correctly add the insert, update and delete commands to a MySqlDataAdapter that contains an INNER JOIN between 2 tables ?
I know that each table must be in a different data adapter, and they are. The "4521studenti" table is inside "mv_dtAdapterStudenti", which is not included in the code above.
Thank you for the help and I hope this won't be considered as a bad post. :)
Okey. I think I've figured it out.
This is the SELECT command for 4521observatii:
string lv_sStudent = "`" + mv_sDatabase + "`.`" + mv_sGroup + "studenti`";
string lv_sObservatii = "`" + mv_sDatabase + "`.`" + mv_sGroup + "observatii`";
string lv_sObservatiiCommand = "SELECT o.idObservatie, o.idStudent, s.nume, o.observatie, o.lastUpdate FROM " + lv_sObservatii + " o INNER JOIN " + lv_sStudent + " s USING (idStudent) ORDER BY s.nume ASC";
// Read data from the server for the current table and add it to the DataSet
mv_dtAdapterObservatii = new MySqlDataAdapter(lv_sObservatiiCommand, mv_sqlConnection);
mv_dtAdapterObservatii.Fill(mv_dsTables, lv_sCurrentTable);
And this is the code for the UPDATE command, inside a different method:
// `iec211`.`4521observatii`
string lv_sObsTB = "`" + mv_sDatabase + "`.`" + mv_sGroup + "observatii`";
// `iec211`.`4521studenti`
string lv_sStudTB = "`" + mv_sDatabase + "`.`" + mv_sGroup + "studenti`";
string lv_sSelectStudenti = "(SELECT idStudent FROM " + lv_sStudTB + " WHERE idStudent=#idStudent)";
string lv_sCommand = "UPDATE " + lv_sObsTB + " SET idStudent="+ lv_sSelectStudenti + ", observatie=#observatie WHERE idObservatie=#idObservatie";
MySqlCommand lv_sqlCommand = new MySqlCommand(lv_sCommand);
lv_sqlCommand.Parameters.Add("#idStudent", MySqlDbType.Int16, 10, "idStudent");
lv_sqlCommand.Parameters.Add("#observatie", MySqlDbType.VarChar, 255, "observatie");
lv_sqlCommand.Parameters.Add("#idObservatie", MySqlDbType.Int16, 10, "idObservatie");
mv_dtAdapterObservatii.UpdateCommand = lv_sqlCommand;
mv_dtAdapterObservatii.UpdateCommand.Connection = mv_sqlConnection;
The idea is that when I use INNER JOIN I bring data from two different tables and put them together. When I used the UPDATE command, the program didn't know which table he was using and gived those errors.
So I thought what if I update the values of 4521observatii and for the column that is used as FOREIGN KEY I assign the value from 4521studenti.
I know it's like "Tell me your name so I can tell you your name.", but it worked for me.
I hope this will help others and you have a better and cleaner solution, pleas tell me :)
I am currently trying to use an sql join statement to bring back results needed for my program. When i try to change one of the database names to a variable, it is displaying an exception of "System.Data.SqlClient.SqlException (0X80131904): Incorrect syntax near '.'" Both databases are on the same SQL server. If i use one of the database names in the string, it connects and the statement is executed as intended. This only occurs when i put the database name as a parameter:
using (var command = new SqlCommand("select p.Tablefield, P.TableFeild, es.SynchronousIn, es.SynchronousOut, " +
"es.dddd, es.MessageName, es.MessageDate from database.xxx.xxx es " +
"join #Database.dbo.xxxx p on p.GUID = es.dddd where es.MessageName = #MessageType and " +
"(es.MessageDate >= #date and es.MessageDate < #date)" +
"and es.dddd = #ddddd " +
"order by MessageDate DESC" , connection))
The #Database Parameter is defined afterwards:
command.Parameters.Add("#Database", SqlDbType.NVarChar);
command.Parameters["#Database"].Value = DatabaseName;
Any ideas at all? I know this might not be the best way of doing this, I am pretty new to the SQL aspect of c# and would like to know if this is possible. I have replaced certain fields with XXXX or DDDD as this is a tool i am hoping to write for my company.
You can not pass the database name as a parameter. You can add it using String.Format on the sql command string.
Something like this:
String.Format("select p.Tablefield, P.TableFeild, es.SynchronousIn, es.SynchronousOut, " +
"es.dddd, es.MessageName, es.MessageDate from database.xxx.xxx es " +
"join {0}.dbo.xxxx p on p.GUID = es.dddd where es.MessageName = #MessageType and " +
"(es.MessageDate >= #date and es.MessageDate < #date)" + "and es.dddd = #ddddd " +
"order by MessageDate DESC", DatabaseName);
Check the following:
String.Format("select p.Tablefield, P.TableFeild, es.SynchronousIn, es.SynchronousOut, " +
"es.dddd, es.MessageName, es.MessageDate from database.xxx.xxx es " +
"join {0}.dbo.xxxx p on p.GUID = es.dddd where es.MessageName = #MessageType and " +
"(es.MessageDate >= #date and es.MessageDate < #date)" + "and es.dddd = #ddddd " +
"order by MessageDate DESC", DatabaseName);
You cannot pass the table name as a parameter. You could just insert the table name into the SQL string using string.Format. Something like..
using (var command = new SqlCommand("select p.Tablefield, P.TableFeild, es.SynchronousIn, es.SynchronousOut, " +
"es.dddd, es.MessageName, es.MessageDate from database.xxx.xxx es " +
string.Format("join #{0}.dbo.{1} p on p.GUID = es.dddd where es.MessageName = #MessageType and ",databaseName,tableName) +
"(es.MessageDate >= #date and es.MessageDate < #date)" +
"and es.dddd = #ddddd " +
"order by MessageDate DESC" , connection))
Be sure to check this value for SQL injection if it is in any way manipulated from the user interface.
I've tried this:
select * from ourschema.mytable
where contains(mysearchablefield, #searchTerms) = 1;
Where #searchTerms was set to "search terms"
Unfortunately, it only produced an error:
ERROR [42610] [IBM][DB2/NT] SQL0418N A statement contains a use of a parameter marker that is not valid. SQLSTATE=42610
Is there a way to use parameterized queries for text search with DB2? If not, is there a document which describes the syntax in detail for manual (ugh) escaping of the search terms (quotes, etc)?
Instead of #field you need to use "?". Everything is basically the same.
Okay, here is a live code sample.
sqlStmt = "SELECT COMPLAINT_NUMBER, VIOLATION_NUMBER, COMMON_ADDRESS_KEY, " +
"DEPT_CODE, DEPT_CODE_DESC, DIVISION_CODE, DIVISION_CODE_DESC, " +
"EMPLOYEE_NAME, COMPLAINT_CODE, COMPLAINT_CODE_DESC, COMPLAINT_DATE, " +
"COMMON_ADDRESS_OWNER, RESOLUTION_CODE, 1 AS SORTORDER " +
"FROM QMFILES/NVMASTP " +
"WHERE VCLOSEDATE = 0 AND " +
"DEPT_CODE LIKE #DEPT_CODE1 AND " +
"DIVISION_CODE LIKE #DIVISION_CODE1 AND " +
"COMPLAINT_DATE BETWEEN #FROM_COMPLAINT_DATE1 AND #TO_COMPLAINT_DATE1 " +
statusQry +
"UNION " +
"SELECT COMPLAINT_NUMBER, VIOLATION_NUMBER, COMMON_ADDRESS_KEY, " +
"DEPT_CODE, DEPT_CODE_DESC, DIVISION_CODE, DIVISION_CODE_DESC, " +
"EMPLOYEE_NAME, COMPLAINT_CODE, COMPLAINT_CODE_DESC, COMPLAINT_DATE, " +
"COMMON_ADDRESS_OWNER, RESOLUTION_CODE, 2 AS SORTORDER " +
"FROM QMFILES/NVMASTP " +
"WHERE VCLOSEDATE <> 0 AND " +
"DEPT_CODE LIKE #DEPT_CODE2 AND " +
"DIVISION_CODE LIKE #DIVISION_CODE2 AND " +
"COMPLAINT_DATE BETWEEN #FROM_COMPLAINT_DATE2 AND #TO_COMPLAINT_DATE2 " +
statusQry +
"ORDER BY DEPT_CODE, DIVISION_CODE, COMPLAINT_CODE, SORTORDER";
iDB2Command cmd = new iDB2Command(sqlStmt, conn);
conn.Open();
cmd.DeriveParameters();
conn.Close();
cmd.Parameters["#DEPT_CODE1"].Value = dept;
cmd.Parameters["#DIVISION_CODE1"].Value = serviceArea;
cmd.Parameters["#DEPT_CODE2"].Value = dept;
cmd.Parameters["#DIVISION_CODE2"].Value = serviceArea;
cmd.Parameters["#FROM_COMPLAINT_DATE1"].Value = Convert.ToDecimal(fromDateString);
cmd.Parameters["#TO_COMPLAINT_DATE1"].Value = Convert.ToDecimal(toDateString);
cmd.Parameters["#FROM_COMPLAINT_DATE2"].Value = Convert.ToDecimal(fromDateString);
cmd.Parameters["#TO_COMPLAINT_DATE2"].Value = Convert.ToDecimal(toDateString);
I hope this helps you out more.