oraclecommand.executenonquery()执行结果问题

wj0728 2008-07-14 02:04:27
在winform中使用oraclecommand.executenonquery()执行一个正确的存储过程,为什么执行结束后在数据库中显示无效(存储过程已被更新),编译也不管用,但是使用数据库工具执行后就显示有效,有没有哪位碰到过同样的问题,希望能够帮忙解答。
...全文
345 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
wj0728 2008-07-22
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 wj0728 的回复:]
具体代码如下:

C# code
fn = of_dialog.FileName; --此处为openfiledialog中选择的文件,假定该文件为存储过程
string comm = File.ReadAllText(fn, Encoding.Default);

string returnmess = RunSql(comm,连接字符串); --此处调用下面的执行方法


public string RunSql(string sqlcommand,string cs)
{
string mess = null;
string conn = cs; …
[/Quote]


现在是这样,如果我打开的文件不是存储过程,就是一个单独的语句,不加那个语句类型不可以吗?
wj0728 2008-07-22
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 mail_ricklee 的回复:]
finally
{
oc.Close();
if (mess == null)
{
mess = "操作区域信息:\r\n" + cs + "\r\n\r\n脚本执行成功;\r\n_______________________\r\n\r\n";
}
else
{
mess = "操作区域信息:\r\n" + cs + "\r\n\r\n脚本执行失败,错误信息:" + "…
[/Quote]



public string RunSql(string sqlcommand,string cs)
{
string mess = null;

难道这个mess不为null?
wj0728 2008-07-22
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 wjp_116 的回复:]
大哥,你从文件里读的内容能叫存储过程吗?
您这概念咋学的?
你从文件里读出的string comm 你可以设置断点看看它的值
是不是符合P_SQL的语法规则,或者MessageBox.show(comm)
[/Quote]


.prc的文件不叫存储过程?有些东西希望能够考虑清楚了再说
ojekleen 2008-07-21
  • 打赏
  • 举报
回复

public string RunSql(string sqlcommand,string cs)
{
string mess = null;
string conn = cs;
OracleConnection oc = new OracleConnection(conn);
OracleCommand ocd = new OracleCommand(sqlcommand, oc); //sqlcommand为存储过程名称
ocd.commandtype=commandtype.StoredProcedure;
try
{
oc.Open();
ocd.ExecuteNonQuery();
}
catch (OracleException oe)
{
mess = oe.Message;
}
finally
{
oc.Close();
if (mess == null)
{
mess = "操作区域信息:\r\n" + cs + "\r\n\r\n脚本执行成功;\r\n_______________________\r\n\r\n";
}
else
{
mess = "操作区域信息:\r\n" + cs + "\r\n\r\n脚本执行失败,错误信息:" + "\r\n\r\n" + mess.ToString() + "\r\n_______________________\r\n\r\n";
}

}
return mess;

}

wjp_116 2008-07-21
  • 打赏
  • 举报
回复
大哥,你从文件里读的内容能叫存储过程吗?
您这概念咋学的?
你从文件里读出的string comm 你可以设置断点看看它的值
是不是符合P_SQL的语法规则,或者MessageBox.show(comm)
mail_ricklee 2008-07-21
  • 打赏
  • 举报
回复
还有,sql发出来see see
mail_ricklee 2008-07-21
  • 打赏
  • 举报
回复
finally
{
oc.Close();
if (mess == null)
{
mess = "操作区域信息:\r\n" + cs + "\r\n\r\n脚本执行成功;\r\n_______________________\r\n\r\n";
}
else
{
mess = "操作区域信息:\r\n" + cs + "\r\n\r\n脚本执行失败,错误信息:" + "\r\n\r\n" + mess.ToString() + "\r\n_______________________\r\n\r\n";
}

}
这个mess不会为null吧
wj0728 2008-07-16
  • 打赏
  • 举报
回复
fn = of_dialog.FileName;

此处fn也为string 类型
wj0728 2008-07-16
  • 打赏
  • 举报
回复
具体代码如下:

fn = of_dialog.FileName; --此处为openfiledialog中选择的文件,假定该文件为存储过程
string comm = File.ReadAllText(fn, Encoding.Default);

string returnmess = RunSql(comm,连接字符串); --此处调用下面的执行方法


public string RunSql(string sqlcommand,string cs)
{
string mess = null;
string conn = cs;
OracleConnection oc = new OracleConnection(conn);
OracleCommand ocd = new OracleCommand(sqlcommand, oc);
try
{
oc.Open();
ocd.ExecuteNonQuery();
}
catch (OracleException oe)
{
mess = oe.Message;
}
finally
{
oc.Close();
if (mess == null)
{
mess = "操作区域信息:\r\n" + cs + "\r\n\r\n脚本执行成功;\r\n_______________________\r\n\r\n";
}
else
{
mess = "操作区域信息:\r\n" + cs + "\r\n\r\n脚本执行失败,错误信息:" + "\r\n\r\n" + mess.ToString() + "\r\n_______________________\r\n\r\n";
}

}
return mess;

}

wj0728 2008-07-16
  • 打赏
  • 举报
回复
怎么没人遇到过这种问题吗?
stning 2008-07-14
  • 打赏
  • 举报
回复
贴代码上来看看
yilanwuyu123 2008-07-14
  • 打赏
  • 举报
回复
那就是在代码有问题 贴代码上来看看

110,032

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧