日期:2014-05-20 浏览次数:21062 次
private void Button1_Click(object sender, EventArgs e) //鼠标点击事件添加 { Product p = new Product(); p.State = 0; p.Createtime = DateTime.Now; int no = insert(p); p = getById(no); //这里面的get.ById(no)里面有错 AddProduct(p); } public static getById(int no) { string sql = "select * from tip where no=?"; OleDbParameter[] parameters = new OleDbParameter[1]; parameters[0] = new OleDbParameter("@no", OleDbType.Integer); parameters[0].Value = no; DataSet ds = AccessDBUtil.ExecuteQuery(sql, parameters); return Row2Product(ds.Tables["ds"].Rows[0]); //执行时这里显示错误,在位置0处没有發現任何行 } //执行查询语句,返回dataset public static DataSet ExecuteQuery(string sql, OleDbParameter[] parameters) { String connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Notes.mdb"; OleDbConnection connection = new OleDbConnection(connectionString) DataSet ds = new DataSet(); connection.Open(); OleDbDataAdapter da = new OleDbDataAdapter(sql, connection); da.SelectCommand.Parameters.AddRange(parameters); da.Fill(ds, "ds"); return ds; } //------------------------------------下面的应该不是很重要----------------------------------------------- //product类 public class Product { private int no; private int state; public Product() { } public int No { get { return no; } set { no = value; } } public int State { get { return state; } set { state = value; } } } //添加到listview private void AddProduct(Product p) { ListViewItem lvi; if(p.State==0) //如果等于0就用第一副图片,等于1就用第二副图片 lvi = this.listView1.Items.Add("",0); else lvi = this.listView1.Items.Add("",1); lvi.SubItems.Add(p.No.ToString()); }