怎样对SQL语句进行错误判断? 用SQL Profiler檢查每個SQL語句的執行 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以使用异常处理,可以停止执行后面的语句,并显示一条提示信息,然后返回主界面。或者使用Transatcion事务,支持backroll达到停止执行后面的语句 try{ ............. 执行你的Sql语句;}catch(Exception ex) { MessageBox.Show("数据库操作错误:"+ex.Message,"错误",MessageBoxButtons.OK,MessageBoxIcon.Error);......................//返回主界面代码 } finally { if(mCn==ConnectionState.Open) { mCn.Close(); } } 最好写一个错误捕作类把所有的SQL错误ID号进行Catch(SqlException me){} 大家说的方法都不行,我的代码如下(直贴出主要代码)try{ mCommand=new SqlDataAdapter(); sqlSelectCommand1=new SqlCommand(); mCommand.SelectCommand=sqlSelectCommand1; sqlSelectCommand1.CommandText=textBox1.text;// sqlSelectCommand1.Connection=mConnection; mCommand.Fill(ds);//如果textBox1.text中的语句错误,执行到这一句就会出错. //我想如果textBox1.text中的语句错误,就停止执行后面的语句,并返回主界面.}catch(System.Exception E){ MessageBox.Show(E.ToString());} 你去查查msn里面有一些多少的ID号为数字的不同的错误结果的用try{.....}catch(Exception h){........}finally{......} vs中可以单步调试存储过程,当然也就可以测试SQL语句 try{}catch (SqlExcepiton e){ }这样呢? 把sql语句放到Sql Server的查询分析器里面去就可以判断什么地方出错了! 下面的语句应该没有问题啊try{ mCommand=new SqlDataAdapter(); sqlSelectCommand1=new SqlCommand(); mCommand.SelectCommand=sqlSelectCommand1; sqlSelectCommand1.CommandText=textBox1.text;// sqlSelectCommand1.Connection=mConnection; mCommand.Fill(ds);}catch(System.Exception E){ MessageBox.Show(E.Message);}finally { sqlSelectCommand1.Connection.Close(); } mCommand=new SqlDataAdapter(); sqlSelectCommand1=new SqlCommand(); mCommand.SelectCommand=sqlSelectCommand1; sqlSelectCommand1.CommandText=textBox1.text;// sqlSelectCommand1.Connection=mConnection;try{ mCommand.Fill(ds);}catch(System.Excfeption e){ MessageBox.show(e.Tostring)}finally{sqlSelectCommand1.Connection.Close();} private void Test() { string strConnectionString = "server=(local);user id=sa;password=xu;database=Northwind;Connect timeout=600"; SqlDataAdapter daSql = new SqlDataAdapter(); SqlConnection cnSql = new SqlConnection(strConnectionString); cnSql.Open(); SqlTransaction tsSql=cnSql.BeginTransaction(); try { SqlCommand cmdQuery = new SqlCommand(); cmdQuery.Connection = cnSql; cmdQuery.Transaction = tsSql; cmdQuery.CommandText = textBox1.Text; cmdQuery.ExecuteNonQuery(); } catch(System.Exception E) { MessageBox.Show(E.Message); } finally { tsSql.Rollback(); cnSql.Close(); } } C#结构体作为函数参数传入,怎么弄? 请教问题 真正高手帮忙,求c#实现的Delauny三角剖分算法,最好是分治算法实现 C# 中 md5 大家来找茬之难度篇 【求助】怎样知道哪台机器在监听6000端口 treeview的问题 WinForm 窗体中不同按钮控制动态产生的不同的 timmer 的启停 ★ 看完这则报道,我很迷惑:为什么微软决定从SCO那里取得Unix使用授权!请各位达人指点★ 网上有免费的C#开发工具吗?帮忙介绍一个 关于windows的datagrid简单问题,在线等 初学 字符转时间 delphi
{
.............
执行你的Sql语句;
}
catch(Exception ex)
{
MessageBox.Show("数据库操作错误:"+ex.Message,"错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
......................
//返回主界面代码
}
finally
{
if(mCn==ConnectionState.Open)
{
mCn.Close();
}
}
Catch(SqlException me)
{}
try
{
mCommand=new SqlDataAdapter();
sqlSelectCommand1=new SqlCommand();
mCommand.SelectCommand=sqlSelectCommand1;
sqlSelectCommand1.CommandText=textBox1.text;//
sqlSelectCommand1.Connection=mConnection;
mCommand.Fill(ds);//如果textBox1.text中的语句错误,执行到这一句就会出错.
//我想如果textBox1.text中的语句错误,就停止执行后面的语句,并返回主界面.
}
catch(System.Exception E)
{
MessageBox.Show(E.ToString());
}
里面有一些多少的ID号为数字的不同的错误结果的
用
try
{
.....
}
catch(Exception h)
{
........
}
finally
{
......
}
{}
catch (SqlExcepiton e)
{
}这样呢?
!
try
{
mCommand=new SqlDataAdapter();
sqlSelectCommand1=new SqlCommand();
mCommand.SelectCommand=sqlSelectCommand1;
sqlSelectCommand1.CommandText=textBox1.text;//
sqlSelectCommand1.Connection=mConnection;
mCommand.Fill(ds);
}
catch(System.Exception E)
{
MessageBox.Show(E.Message);
}finally
{
sqlSelectCommand1.Connection.Close();
}
mCommand=new SqlDataAdapter();
sqlSelectCommand1=new SqlCommand();
mCommand.SelectCommand=sqlSelectCommand1;
sqlSelectCommand1.CommandText=textBox1.text;//
sqlSelectCommand1.Connection=mConnection;
try
{
mCommand.Fill(ds);
}catch(System.Excfeption e)
{
MessageBox.show(e.Tostring)
}finally
{
sqlSelectCommand1.Connection.Close();
}
{
string strConnectionString = "server=(local);user id=sa;password=xu;database=Northwind;Connect timeout=600";
SqlDataAdapter daSql = new SqlDataAdapter();
SqlConnection cnSql = new SqlConnection(strConnectionString);
cnSql.Open();
SqlTransaction tsSql=cnSql.BeginTransaction();
try
{
SqlCommand cmdQuery = new SqlCommand();
cmdQuery.Connection = cnSql;
cmdQuery.Transaction = tsSql;
cmdQuery.CommandText = textBox1.Text;
cmdQuery.ExecuteNonQuery();
}
catch(System.Exception E)
{
MessageBox.Show(E.Message);
} finally
{
tsSql.Rollback();
cnSql.Close();
}
}