C#运行时出现用户代码未处理SQL Exception,如何解决? 5
usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Data;usingSy...
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace Chulicheng
{
public class mer
{
SqlConnection con = new SqlConnection("server=(local);uid=sa;pwd=sa;database=student");
public bool insertReun(string sql)
{
SqlCommand comm = new SqlCommand(sql,con);
con.Open();
if (comm.ExecuteNonQuery() > 0)
{
return true;
}
else
{
return false;
}
}
public DataSet SelectReun(string sql)
{
try
{
SqlDataAdapter da = new SqlDataAdapter(sql, this.con);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
catch (Exception)
{
throw;
}
}
public bool DeleteReun(string sql)
{
SqlCommand comm = new SqlCommand(sql,con);
con.Open();
if (comm.ExecuteNonQuery() > 0)
{
return true;
}
else
{
return false;
}
}
public bool UpdateReun(string sql,SqlParameter[] param)
{
SqlCommand comm = new SqlCommand(sql,con);
comm.Parameters.AddRange(param);
con.Open();
if (comm.ExecuteNonQuery() > 0)
{
return true;
}
else
{
return false;
}
}
public bool SelectReud(string sql)
{
SqlCommand comm = new SqlCommand(sql, con);
con.Open();
return (int)comm.ExecuteScalar() > 0 ? true : false;
}
}
}
con.open()处出现错误提示。 展开
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace Chulicheng
{
public class mer
{
SqlConnection con = new SqlConnection("server=(local);uid=sa;pwd=sa;database=student");
public bool insertReun(string sql)
{
SqlCommand comm = new SqlCommand(sql,con);
con.Open();
if (comm.ExecuteNonQuery() > 0)
{
return true;
}
else
{
return false;
}
}
public DataSet SelectReun(string sql)
{
try
{
SqlDataAdapter da = new SqlDataAdapter(sql, this.con);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
catch (Exception)
{
throw;
}
}
public bool DeleteReun(string sql)
{
SqlCommand comm = new SqlCommand(sql,con);
con.Open();
if (comm.ExecuteNonQuery() > 0)
{
return true;
}
else
{
return false;
}
}
public bool UpdateReun(string sql,SqlParameter[] param)
{
SqlCommand comm = new SqlCommand(sql,con);
comm.Parameters.AddRange(param);
con.Open();
if (comm.ExecuteNonQuery() > 0)
{
return true;
}
else
{
return false;
}
}
public bool SelectReud(string sql)
{
SqlCommand comm = new SqlCommand(sql, con);
con.Open();
return (int)comm.ExecuteScalar() > 0 ? true : false;
}
}
}
con.open()处出现错误提示。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询