开发者

error: sql command not properly ended

I have to search the employee details, which is contained within 3 tables. I have used joins in the query query, but it shows error when I press the search button:

sql command not properly ended

c# coding:

try {
  //Search Employee Details
  Oracle.DataAccess.Client.OracleConnection cn = new Oracle.DataAccess.Client.OracleConnection();

  cn.ConnectionString = "user id=system; password=system;";
  Oracle.DataAccess.Client.OracleCommand cmd = new Oracle.DataAccess.Client.OracleCommand();

  cmd.Connection = cn;
  //cn = new Oracle.DataAccess.Client.OracleConnection();
  cmd.CommandText = " select deposit.loanid, 
                             form1.empedoj, 
                             form1.empshare, 
                             sharecapital.shareint, 
                             sharecapital.loandt, 
                             sharecapital.loandeduc, 
                             sharecapital.dividend, 
                             sharecapital.sharetot 
                        from form1, 
                             deposit, 
                             sharecapital 
                       where deposit.loanid(+) = sharecapital.loanid = '" + txtlnid.Text.Trim() + "'";  // shows sql command not properly ended

  Oracle.DataAccess.Clie开发者_如何学Pythonnt.OracleDataAdapter ada = new Oracle.DataAccess.Client.OracleDataAdapter(cmd);
  System.Data.DataTable dt = new DataTable();
  dt.Clear();
  ada.Fill(dt);

  //Display in Textbox
  if (dt.Rows.Count > 0) {
    txtlnid.Text = dt.Rows[0].ItemArray[0].ToString();
    admdate.Text = dt.Rows[0].ItemArray[1].ToString();
    txtadmamt.Text = dt.Rows[0].ItemArray[2].ToString();
    txtadmint.Text = dt.Rows[0].ItemArray[3].ToString();
    loandt.Text = dt.Rows[0].ItemArray[4].ToString();
    txtlnamt.Text = dt.Rows[0].ItemArray[5].ToString();
    txtlnint.Text = dt.Rows[0].ItemArray[6].ToString();
    txtsctot.Text = dt.Rows[0].ItemArray[7].ToString();
  }

  if (cn.State == ConnectionState.Closed) {
    cn.Open();
  }

  string str;
  str = cmd.ExecuteScalar().ToString();

  if (str != null) {
    MessageBox.Show("Record Found");
  } else {
    MessageBox.Show("ID not Match");
  }
} catch (Exception ex) {
  MessageBox.Show(ex.Message);
}


Your SQL statement becomes

  SELECT DEPOSIT.LOANID,
         FORM1.EMPEDOJ,
         FORM1.EMPSHARE,
         SHARECAPITAL.SHAREINT,
         SHARECAPITAL.LOANDT,
         SHARECAPITAL.LOANDEDUC,
         SHARECAPITAL.DIVIDEND,
         SHARECAPITAL.SHARETOT
  FROM   FORM1, DEPOSIT, SHARECAPITAL
  WHERE  DEPOSIT.LOANID(+) = SHARECAPITAL.LOANID =    '" + txtlnid.Text.Trim() + "'";

I suspect it should be:

  SELECT DEPOSIT.LOANID,
         FORM1.EMPEDOJ,
         FORM1.EMPSHARE,
         SHARECAPITAL.SHAREINT,
         SHARECAPITAL.LOANDT,
         SHARECAPITAL.LOANDEDUC,
         SHARECAPITAL.DIVIDEND,
         SHARECAPITAL.SHARETOT
  FROM   FORM1, DEPOSIT, SHARECAPITAL
  WHERE  DEPOSIT.LOANID(+) = SHARECAPITAL.LOANID 
  AND    SHARECAPITAL.LOANID = '" + txtlnid.Text.Trim() + "'";

Also, you have a 3-table join without the correct join conditions, the query is highly likely to return a Cartesian product.


Have you tried putting a semicolon at the end of your query string?

cmd.CommandText = " select deposit.loanid, form1.empedoj, form1.empshare,
sharecapital.shareint, sharecapital.loandt, sharecapital.loandeduc, 
sharecapital.dividend, sharecapital.sharetot from form1, deposit , 
sharecapital where deposit.loanid(+) = sharecapital.loanid = '" + txtlnid.Text.Trim() + "';";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜