程序首先是要判断一天信息是否存在于数据库中,然后若存在则将数据展示在页面的ListView中。
用来两种方法:
1.用Adapter
private static string strConnect = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = " +
"C:\\Users\\Administrator\\Desktop\\db\\TEACHER.mdb";
private static OleDbConnection conConnection = new OleDbConnection(strConnect);
conConnection.Open();
string strCommand = "SELECT * FROM student where SID = '" + str1 + "'";
DataTable dt = BindData(strCommand);
if (dt.Rows.Count > 0) //判断信息是否存在,有读到信息则count>0
{
ListViewItem item = new ListViewItem(str1); //将每一列的数据添加到页面中的ListView中
item.SubItems.Add(dt.Rows[0]["Sname"].ToString());