private void Button1_Click(object sender, System.EventArgs e)
{
OleDbConnection myConnection = new OleDbConnection("Provider=MSDAORA;User ID=test;Password=test;DataSource=test");
string SelectStr="SELECT id.nextval from dual";
OleDbCommand myCommand = new OleDbCommand(SelectStr,myConnection);
this.oleDbInsertCommand1.CommandText = "INSERT INTO TESTHC(MC, ID) VALUES (?, id.nextval)";
this.oleDbInsertCommand1.Connection = this.oleDbConnection1;
this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("MC", System.Data.OleDb.OleDbType.VarChar, 20, "MC"));
this.oleDbDataAdapter1.InsertCommand.Parameters["mc"].Value=this.TextBox1.Text;
this.oleDbDataAdapter1.InsertCommand.Connection.Open();
this.oleDbDataAdapter1.InsertCommand.ExecuteNonQuery();
this.oleDbDataAdapter1.InsertCommand.Connection.Close();
}
上面的程序可以正确运行,但是为什么我没有ExecuteNonQuery()语句,也没有ExecuteReader()语句,SELECT语句也能执行得到id.nextval的值,并且插入testhc表呢?
{
OleDbConnection myConnection = new OleDbConnection("Provider=MSDAORA;User ID=test;Password=test;DataSource=test");
string SelectStr="SELECT id.nextval from dual";
OleDbCommand myCommand = new OleDbCommand(SelectStr,myConnection);
this.oleDbInsertCommand1.CommandText = "INSERT INTO TESTHC(MC, ID) VALUES (?, id.nextval)";
this.oleDbInsertCommand1.Connection = this.oleDbConnection1;
this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("MC", System.Data.OleDb.OleDbType.VarChar, 20, "MC"));
this.oleDbDataAdapter1.InsertCommand.Parameters["mc"].Value=this.TextBox1.Text;
this.oleDbDataAdapter1.InsertCommand.Connection.Open();
this.oleDbDataAdapter1.InsertCommand.ExecuteNonQuery();
this.oleDbDataAdapter1.InsertCommand.Connection.Close();
}
上面的程序可以正确运行,但是为什么我没有ExecuteNonQuery()语句,也没有ExecuteReader()语句,SELECT语句也能执行得到id.nextval的值,并且插入testhc表呢?
解决方案 »
- 如何获取ENUM成员描述内容
- 一个关于模板页嵌套的小问题 没错 又是我问题哥
- 向一些企业中的大哥们求一些学习使用项目和常用的代码片断。
- ASP.NET中的文件上传相关问题
- 360桌面,或者Q+ 左边那个浮动的侧边栏 固定在桌面的时候会把桌面的图标向右移动一些,请问这个用C#怎么做
- 在datagrid中,通过ButtonColumn,如何取本行某字段的值呢?20分,要C#代码,谢谢啦
- 这哪错了?
- ADO.NET Entity Framework 求教(极度困惑)
- ucase(mid(a(i),1,len(q)))
- 求达人:验证控件失败拦截,导致其他按钮不能回发的问题
- 看看这篇文章,如果你觉得好,顶一下
- 菜鸟学ASP.NET
ado。net的书籍
应该能明白的
this.oleDbInsertCommand1.Connection = this.oleDbConnection1;
this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("MC", System.Data.OleDb.OleDbType.VarChar, 20, "MC"));
this.oleDbDataAdapter1.InsertCommand.Parameters["mc"].Value=this.TextBox1.Text;这就是神奇的地方