定义的集合
public class getinform
{
private string _name;
private string _pic;
private double _price;
public string name
{
get { return _name; }
set { _name = value; }
}
public string pic
{
get { return _pic; }
set { _pic = value; }
}
public double price
{
get { return _price; }
set { _price = value; }
}
}
数据库查询代码
public class selc
{
private string _name;
private string _pic;
private double _price;
public string name
{
get { return _name; }
set { _name = value; }
}
public string pic
{
get { return _pic; }
set { _pic = value; }
}
public double price
{
get { return _price; }
set { _price = value; }
}
}
public List<selc> select(string ID)
{
List<selc> results = new List<selc>();
SqlConnection con = new SqlConnection(_comstring);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "select 产品名称,单价,小图片 from goods where 产品ID=@ID ";
cmd.Parameters.AddWithValue("ID", ID);
using (con)
{
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
selc get = new selc();
get.name = (string)reader["产品名称"];
get.pic = Convert.ToString(reader["小图片"]);
get.price = (double)reader["单价"];
results.Add(get);
}
reader.Close();
}
return results;
}
但是我在前面不能赋值呢
string ID = row1["产品ID"].ToString();
object1 sel = new object1();
getinform getinform =(getinform)sel.select(ID);
public class getinform
{
private string _name;
private string _pic;
private double _price;
public string name
{
get { return _name; }
set { _name = value; }
}
public string pic
{
get { return _pic; }
set { _pic = value; }
}
public double price
{
get { return _price; }
set { _price = value; }
}
}
数据库查询代码
public class selc
{
private string _name;
private string _pic;
private double _price;
public string name
{
get { return _name; }
set { _name = value; }
}
public string pic
{
get { return _pic; }
set { _pic = value; }
}
public double price
{
get { return _price; }
set { _price = value; }
}
}
public List<selc> select(string ID)
{
List<selc> results = new List<selc>();
SqlConnection con = new SqlConnection(_comstring);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "select 产品名称,单价,小图片 from goods where 产品ID=@ID ";
cmd.Parameters.AddWithValue("ID", ID);
using (con)
{
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
selc get = new selc();
get.name = (string)reader["产品名称"];
get.pic = Convert.ToString(reader["小图片"]);
get.price = (double)reader["单价"];
results.Add(get);
}
reader.Close();
}
return results;
}
但是我在前面不能赋值呢
string ID = row1["产品ID"].ToString();
object1 sel = new object1();
getinform getinform =(getinform)sel.select(ID);
解决方案 »
- WPF ContextMenu问题
- 谁能提供一本C#高级编程的下载地址
- 如何直接在代码里把流文件写出来?
- 关于Treeview控件的一个棘手问题,向各位大侠求助!!!恳请高手给出指点,谢谢!!
- 这句话是什么意思啊:此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。
- 请问如何在WPF和Listview中处理按住Ctrl或Shift多选后拖拽的问题?如何使得在拖拽的时候,之前用Ctrl选中的Item继续处于选中状态??!!
- datagrid 超连接怎麽带多个参数
- HELP,请推荐一个高性能文本编辑器带折叠功能
- 验证码验证
- C#读txt文件并写入二维数组中(txt数据行,列未知)
- C#如何获取局域网内在线主机的IP
- 怎么取消 listBox1中的默认选中项。。。。。。
--你结果中都没把它选出来
cmd.CommandText = "select 产品ID,产品名称,单价,小图片 from goods where 产品ID=@ID ";
object1是什么东西?应该是selc吧?
selc sel = new selc();
List<selc> getinform =sel.select(ID);
另外还有
cmd.Parameters.AddWithValue("@ID", ID);
List<selc> selcList =sel.select(ID);
List<getinform > getList=new List<getinform >();
foreach(selc item in selcList )
{
getinform get=new getinform ();
get._name=item._name;
get._pic=item._pic;
get._price=item._price;
getList.add(get);
}