/// <summary>
/// 执行Sql语句SqlStr返回bool(是否存在满足条件的记录)
/// protected static bool ExeSqlExist(string SqlStr)
/// </summary>
/// <param name="SqlStr"></param>
/// <returns></returns>
#region 执行Sql语句SqlStr返回bool(是否存在满足条件的记录)
protected static bool ExeSqlExist(string SqlStr)
{
SqlConnection myCon=new SqlConnection(conStr);
SqlCommand myCom=new SqlCommand(SqlStr,myCon);
try
{
myCon.Open();
SqlDataReader myReader=myCom.ExecuteReader();
if (myReader.Read())
return true;
else
return false; }
catch(System.Data.SqlClient.SqlException e)
{
throw new Exception(e.Message);
}
finally
{
myCom.Dispose();
myCon.Close();
}
}
#endregion
/// 执行Sql语句SqlStr返回bool(是否存在满足条件的记录)
/// protected static bool ExeSqlExist(string SqlStr)
/// </summary>
/// <param name="SqlStr"></param>
/// <returns></returns>
#region 执行Sql语句SqlStr返回bool(是否存在满足条件的记录)
protected static bool ExeSqlExist(string SqlStr)
{
SqlConnection myCon=new SqlConnection(conStr);
SqlCommand myCom=new SqlCommand(SqlStr,myCon);
try
{
myCon.Open();
SqlDataReader myReader=myCom.ExecuteReader();
if (myReader.Read())
return true;
else
return false; }
catch(System.Data.SqlClient.SqlException e)
{
throw new Exception(e.Message);
}
finally
{
myCom.Dispose();
myCon.Close();
}
}
#endregion
sqlDA.UpdateCommand=scb.GetUpdateCommand();
sqlDA.DeleteCommand=scb.GetDeleteCommand();这样,当你把sqlDA的数据放到一个TABLE后,然后通过代码在TABLE中进行数据的修改(删除、添加、更新等),只要调用:
sqlDA.Update(..)
就可以轻松完成。
If Exists (Select *** From *** Where ID = ***)
Update *** Set *** = *** Where ID = ***
Else
Insert.....