|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
一个很大的类库。应用程序之所以难以跨平台,在于直接调用了特定平台的接口,而一个巨大的类库,就能极大地减少应用程序对平台的依赖。asp.net|数据|数据库usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;
usingSystem.Data.SqlClient;
namespaceMysqlserver
{
///<summary>
///SqlServerDataBase的择要申明
///</summary>
publicclassSqlServerDataBase
{
privatestringstrError=null;
privateintintCount=0;
publicSqlServerDataBase()
{
//
//TODO:在此处增加机关函数逻辑
//
}
///<summary>
///公然办法DBConn,前往数据库毗连
///</summary>
///<returns></returns>
publicSqlConnectionDBconn()
{
stringstrConn="Server=(local);Database=GlobalMeetings;Uid=sa;pwd=";
try
{
returnnewSqlConnection(strConn);
}
catch(Exception)
{
returnnull;
}
}
///<summary>
///公然属性ErrorMessage,前往毛病信息
///</summary>
publicstringErrorMessage
{
get
{
returnstrError;
}
}
///<summary>
///依据查询语句从数据库检索数据
///</summary>
///<paramname="strSelect">查询语句</param>
///<paramname="SqlConn">数据库毗连</param>
///<returns>无数据则前往DataSet工具,不然前往null</returns>
publicDataSetSelect(stringSelectString,SqlConnectionsqlConn)
{
strError="";
SqlConnectionconn;
if(sqlConn==null)
{
conn=DBconn();
}
else
{
conn=sqlConn;
}
try
{
//若数据库毗连确当前形态是封闭的,则翻开毗连
if(conn.State==ConnectionState.Closed)
{
conn.Open();
}
SqlDataAdaptermySqlDataAdapter=newSqlDataAdapter();
SqlCommandselectCommand=newSqlCommand(SelectString,conn);
selectCommand.CommandType=CommandType.Text;
mySqlDataAdapter.SelectCommand=selectCommand;
DataSetmyDS=newDataSet();
mySqlDataAdapter.Fill(myDS);
returnmyDS;
}
catch(Exceptione)
{
strError="数据检索失利:"+e.Message;
returnnull;
}
finally
{
if(conn.State!=ConnectionState.Closed)
{
conn.Close();
}
}
}
///<summary>
///更新数据库
///</summary>
///<paramname="UpdateString">UpdateSql语句</param>
///<paramname="SqlConn">数据库毗连</param>
///<returns>更新乐成前往true</returns>
publicboolUpdate(stringUpdateString,SqlConnectionSqlConn)
{
returnudiDataBase(UpdateString,SqlConn);
}
///<summary>
///从数据库中删除数据
///</summary>
///<paramname="DeleteString">DeleteSql语句</param>
///<paramname="SqlConn">数据库毗连</param>
///<returns>删除乐成前往true</returns>
publicboolDelete(stringDeleteString,SqlConnectionSqlConn)
{
returnudiDataBase(DeleteString,SqlConn);
}
///<summary>
///把数据拔出数据库
///</summary>
///<paramname="InsertString">InsertSql语句</param>
///<paramname="SqlConn">数据库毗连</param>
///<returns>拔出乐成前往true</returns>
publicboolInsert(stringInsertString,SqlConnectionSqlConn)
{
returnudiDataBase(InsertString,SqlConn);
}
///<summary>
///依据Sql语句更新数据库
///</summary>
///<paramname="UDIString">更新语句</param>
///<paramname="SqlConn">数据库毗连</param>
///<returns>更新乐成则前往true</returns>
publicbooludiDataBase(stringUDIString,SqlConnectionSqlConn)
{
strError="";
SqlConnectionconn;
if(SqlConn==null)
{
conn=DBconn();
}
else
{
conn=SqlConn;
}
try
{
if(conn.State==ConnectionState.Closed)
{
conn.Open();
}
SqlCommandcmd=newSqlCommand(UDIString,conn);
cmd.CommandType=CommandType.Text;
intCount=cmd.ExecuteNonQuery();
return!(intCount<1);
}
catch(Exceptione)
{
strError="更新数据库失利:"+e.Message;
returnfalse;
}
finally
{
if(conn.State!=ConnectionState.Closed)
{
conn.Close();
}
}
}
}
}
-----------------------------
两种挪用办法
1、stringstrUserPsw=UserPsw.Text.Trim();
stringUserPassword=System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(strUserPsw,"MD5");//md5加密
SqlServerDataBaseobj=newSqlServerDataBase();
obj.Insert("insertintoasUserInfo(UserName,UserPassword,Question,Answer,CreateTime)values("+UserName.Text.Trim()+","+UserPassword+","+Question.Text.Trim()+","+Answer.Text.Trim()+","+DateTime.Now.ToString()+")",null);
2、privateboolIsUsernameExist(stringstrUsername)
{
boolbRet=true;
SqlServerDataBasedb=newSqlServerDataBase();
DataSetds=db.Select("select*fromasUserInfowhereUserName="+strUsername+"",null);
if(ds==null||ds.Tables.Count==0||ds.Tables[0].Rows.Count==0)
{
bRet=false;
}
else
{
bRet=true;
}
returnbRet;
}
我实在想不明白java的机制,为什么非要那么蛋疼,在同一个平台下重复编译。 |
|