我对此错误完全失明。我更像是一个Java人而不是ASP人。所以这是我的代码和我的问题:
以下是产生错误的代码:
protected void ButtonOk_Click(object sender, EventArgs e)
{
// OracleConnection connect = new OracleConnection();
// connect.ConnectionString = ConfigurationManager.ConnectionStrings["Absensi2.Properties.Settings.Setting"].ConnectionString;
//// SqlConnection connect = new SqlConnection(getConnection());
var sql = "insert into master_dosen('NIP','NAMA_DOSEN','KETERANGAN') values (:NIP, :NAMA_DOSEN, :KETERANGAN)";
using (OracleConnection c = new OracleConnection(ConfigurationManager.ConnectionStrings["Absensi2.Properties.Settings.Setting"].ConnectionString))
{
c.Open();
using (OracleCommand cmd = new OracleCommand(sql, c))
{
cmd.Parameters.Add(":NIP", TextBoxNIP.Text);
cmd.Parameters.Add(":NAMA_DOSEN", TextBoxNamaDosen.Text);
cmd.Parameters.Add(":KETERANGAN", TextBoxKeterangan.Text);
cmd.ExecuteNonQuery();
GridView1.DataBind();
}
c.Close();
}
错误是: ORA-00928:缺少SELECT关键字 在行cmd.ExecuteNonQuery();
我已经搜索了,并且说弃用了。这是真的吗?
注意:我正在使用ODP.NET,而我正在使用visual studio 2010。
答案 0 :(得分:4)
您的查询的问题是您使用单引号包装列名称,这使它们成为字符串文字。
要解决此问题,只需删除列名称周围的单引号:
var sql = "insert into master_dosen(NIP,NAMA_DOSEN,KETERANGAN) ...";
答案 1 :(得分:2)
protected void ButtonOk_Click(object sender, EventArgs e)
{
// OracleConnection connect = new OracleConnection();
// connect.ConnectionString = ConfigurationManager.ConnectionStrings["Absensi2.Properties.Settings.Setting"].ConnectionString;
//// SqlConnection connect = new SqlConnection(getConnection());
var sql = "insert into master_dosen(NIP,NAMA_DOSEN,KETERANGAN) values (:NIP, :NAMA_DOSEN, :KETERANGAN)";
using (OracleConnection c = new OracleConnection(ConfigurationManager.ConnectionStrings["Absensi2.Properties.Settings.Setting"].ConnectionString))
{
c.Open();
using (OracleCommand cmd = new OracleCommand(sql, c))
{
cmd.Parameters.Add(":NIP", TextBoxNIP.Text);
cmd.Parameters.Add(":NAMA_DOSEN", TextBoxNamaDosen.Text);
cmd.Parameters.Add(":KETERANGAN", TextBoxKeterangan.Text);
cmd.ExecuteNonQuery();
GridView1.DataBind();
}
c.Close();
}
试试这个它会起作用,我想你错过了sql insert语法