【发布时间】:2014-12-12 19:00:19
【问题描述】:
您好,我是一名学生,我们的教授要求我们做一个基本的 CRUD 程序。现在,我在 C# + mysql 中做了很多 CRUD 程序,但现在我们的教授让我们使用 oracle db,(忘记它是什么。像 10g XE 之类的)并说我们应该使用 oledb。我试图迁移我以前的 c# + mysql 代码,但显然它不起作用。我做了很多搜索,最终导致我这样做
private void button2_Click(object sender, EventArgs e)
{
string commandText = "insert into Procedures (procedureID,petID,visitDate,procedureType) values(:procedureID,:petID,:visitDate,:procedureType)";
con = new OleDbConnection(connectionstring);
OleDbCommand cmd = new OleDbCommand(commandText, con);
con.Open();
dtpDate.Format = DateTimePickerFormat.Custom;
dtpDate.CustomFormat = "dd-MMM-yy";
cmd.Parameters.AddWithValue("procedureID", null);
//i think this line above is the error. correct me if im wrong.
//but how do you pass a null value to a foreign key in oracle?
//in mysql i'd just set my primary key to autoincrement and I would
//just pass a null value and it would automatically set a unique ID
//but in oracle i cannot find autoincrement and i cannot set my primary
//key to nullable. is this the error or did I do something else wrong?
//is oracle's primary key set to autoincrement by default?
cmd.Parameters.AddWithValue("petID", tbName.Text);
cmd.Parameters.AddWithValue("visitDate", dtpDate.Text);
cmd.Parameters.AddWithValue("procedureType", tbProcedure.Text);
cmd.ExecuteNonQuery();
OleDbDataAdapter da = new OleDbDataAdapter("select * from Procedures", con);
DataSet ds = new DataSet();
da.Fill(ds, "Procedures");
dgvTable.DataSource = ds.Tables[0];
con.Dispose();
}
当我尝试插入数据时,它给了我一个“ORA-01008: not all variables bound”错误。
附:如果有帮助,我正在使用 MS Visual Studio 2013。
【问题讨论】:
标签: c# mysql database oracle visual-studio