using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OracleClient;
//using Oracle.DataAccess.Client;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static string constr = "Data source=orcl;User ID =student;Password=student"; //数据库连接字符串
private void button1_Click(object sender, EventArgs e)
{
OracleConnection con = new OracleConnection(constr);
OracleCommand cmd = new OracleCommand("update CLASS_T set name='金融' where teacher='陈老师';", con);
con.Open(); //打开数据连接
cmd.ExecuteNonQuery();
MessageBox.Show("修改成功!");
con.Close();
}
private void button2_Click(object sender, EventArgs e)
{
OracleConnection con = new OracleConnection(constr);
con.Open();
string sql = "select * from class_t";
OracleDataAdapter oda1 = new OracleDataAdapter(sql, con);
DataSet ds1 = new DataSet();
oda1.Fill(ds1);
dataGridView1.DataSource = ds1.Tables[0];
con.Close();
}
}
}
新手,sql语句验证过是正确的,数据库连接也没问题,button2_Click数据可以出来,就是update或者insert时到cmd.ExecuteNonQuery();就报错了
------解决思路----------------------
sql里面最后的冒号去掉,原因你可以查下oracle 冒号