这两种绑定数据库的方式有什么不同?在线等。。。
一种是直接把记录集绑定:
public void BindDropDownList(string str,DropDownList myDropDownList,string valueField,string textField)
{
Comm = new OleDbCommand(str , Conn);
dr = Comm.ExecuteReader();
myDropDownList.DataSource = dr;
myDropDownList.DataValueField = valueField;
myDropDownList.DataTextField = textField;
myDropDownList.DataBind();
dr.Close();
}
另一种是通过dataset绑定:
public void Fill(string str)
{
OleDbAdapter = new OleDbDataAdapter(str,Conn);
ds = new DataSet();
OleDbAdapter.Fill(ds);
}
public void BindDropDownListDs(string strSql, DropDownList myDropDownList, string valueField, string textField)
{
Fill(strSql);
myDropDownList.DataSource = ds.Tables[0].DefaultView;
myDropDownList.DataTextField = textField;
myDropDownList.DataValueField = valueField;
myDropDownList.DataBind();
}
问题1:如果说第一种是直接建立连接,操作数据库。第二种是把数据先用Dataset加载到内存中,再更新。那么请问,这两种方式那一种比较好?分别适用于什么样的情况。
问题2:请看下面这段代码,“清除HTML文件的代码和SQL指定的代码”什么意思,这个方法是干嘛用的,什么时候用?
代码:
///<summary>
///清除HTML文件的代码和SQL指定的代码
///</summary>
///<param name="Str"></param>
///<returns></returns>
public string SetNOHtmlChr(string Str)
{
Str = Str.Replace("'", "’");
Str = Str.Replace("<", "〈");
Str = Str.Replace(">", "〉");
return Str;
}
多谢指教。