類管理解析

iDotNetSpace發表於2010-04-07

sql語句:

insert into table () values ()

update table set a= @a,b= @b where ID = @ID

delete from table where Id = @Id

 

執行命令

public  static int ExecuteNonQuerty(DbCommand command)

{

int a = -1;

try

{

command.connection.Open();

a =  command.ExecuteNonQuery():

}

catch (Exception Ex)

{

throw Ex.ToString();

}

finally

{

command.connection.Close();

}

return a;

}

 

判斷是否執行成功

public static bool update(DbCommand command)

{

int result = -1;

try

{

result  =  DB.ExecuteNonQuery(command)

}

catch

{

}

return (result!=-1);

}

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12639172/viewspace-631500/,如需轉載,請註明出處,否則將追究法律責任。

相關文章