JavaScript与Web Service组合实现无刷新交互(扩展)--查询数据库
2010-09-14 13:32:00 来源:WEB开发网四:建立UserInfoCompontent,封装数据的查询功能,详细定义如下所示:
public class UserInfoComponent
{
private string _strCon;
public string StrCon
{
get { return _strCon; }
set { _strCon = value; }
}
public UserInfoComponent()
{
this.StrCon = ConfigurationManager.AppSettings["ConnectionString"];
}
public DataSet QueryAll()
{
string commandText = "Select * from UserInfo";
return QueryUserInfo(commandText);
}
public UserInfo Query(int userId)
{
string commandText = "Select * from UserInfo where userId=" + userId;
DataTable dt = QueryUserInfo(commandText).Tables[0];
UserInfo user = new UserInfo(int.Parse(dt.Rows[0][0].ToString()),
dt.Rows[0][1].ToString(),
dt.Rows[0][2].ToString(),
dt.Rows[0][3].ToString(),
dt.Rows[0][4].ToString(),
dt.Rows[0][5].ToString());
return user;
}
public DataSet QueryUserInfo(string commandText)
{
using (SqlConnection conn = new SqlConnection(StrCon))
{
using (SqlDataAdapter sda = new SqlDataAdapter(commandText, conn))
{
using (DataSet ds = new DataSet())
{
sda.Fill(ds);
return ds;
}
}
}
}
}
Tags:JavaScript Web Service
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接