过去几天我无法将任何固定参数传递给我的SQL查询。 我尝试了所有可能的教程将参数传递给查询,但没有任何作用。
但是,我已经看到通过将固定参数直接放在查询(方法1)中它完美地工作。
我没有看到方法2中的功能阻止了我的功能。
当我说它不起作用时,在第一种方法中我的读者被填充而在方法2中我的读者是空的
方法1:有效(我不需要这种功能)
public void VerifierVersionDejaPresnte(ParseurXML.DonneesGlobales donneGlobale)
{
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "select nom_projet from analyses where nom_projet='demonstration'";
cmd.CommandType = CommandType.Text;
OracleDataReader dr = cmd.ExecuteReader();
if (dr.Read())
Console.WriteLine("Data already exist");
else
Console.WriteLine("Data doesn't exist");
}
方法2:不起作用(我需要这种功能)
public void VerifierVersionDejaPresnte(ParseurXML.DonneesGlobales donneGlobale)
{
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "select nom_projet from analyses where nom_projet=:test";
cmd.Parameters.Add(new OracleParameter("test", "demonstration"));
cmd.CommandType = CommandType.Text;
OracleDataReader dr = cmd.ExecuteReader();
if (dr.Read())
Console.WriteLine("Data already exist");
else
Console.WriteLine("Data doesn't exist");
}
答案 0 :(得分:0)
public void VerifierVersionDejaPresnte(ParseurXML.DonneesGlobales donneGlobale)
{
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "select nom_projet from analyses where nom_projet=:test";
cmd.Parameters.Add(new OracleParameter(":test", "demonstration"));
cmd.CommandType = CommandType.Text;
OracleDataReader dr = cmd.ExecuteReader();
if (dr.Read())
Console.WriteLine("Data already exist");
else
Console.WriteLine("Data doesn't exist");
}
答案 1 :(得分:0)
String updateCmd;
SqlCommand myCommandUpd;
updateCmd =" UPDATE RHRMVacationRequest SET [EmplId] = @Emplid WHERE RecId = @ RecId&#34 ;;
myCommandUpd = new SqlCommand(updateCmd, DataBase.GetConnetionToBase());
myCommandUpd.Parameters.Add(new SqlParameter("@Emplid", SqlDbType.VarChar, 10));
myCommandUpd.Parameters.Add(new SqlParameter("@RecId", SqlDbType.BigInt));
myCommandUpd.Parameters["@Emplid"].Value = emplIdUpd.Text.Trim();
myCommandUpd.Parameters["@RecId"].Value = Convert.ToInt64(RecIdUpd.Value.Trim());
myCommandUpd.Connection.Open();
myCommandUpd.ExecuteNonQuery();
答案 2 :(得分:0)
经过数小时的研究,我终于找到了解决方案:
public Boolean VerifierVersionDejaPresnte(ParseurXML.DonneesGlobales donneGlobale)
{
string str = "demonstration";
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.BindByName = true;
cmd.CommandText = "select * from analyses where nom_projet='"+str+"'";
cmd.CommandType = CommandType.Text;
OracleDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Console.WriteLine("Data already exist");
return true;
}
Console.WriteLine("Data doesn't already exist");
return true;
}