下面是C#的基本操作数据库功能:
public Ilist(Student) GetAllStudent()
{
IList<Student> alist = new List<Student>();
string sql = "select * from Students";
SqlDataAdapter da = new SqlDataAdapter(sql,DBHelper.Connection);
DataTable dt = new DataTable();
da.Fill(dt);
foreach (DataRow row in dt.Rows)
{
Student stu = new Student();
ar.StudentWeight =float.Parse(row["studentWeight"].ToString());
//上面这句代码一运行就报错:输入字符串不正确
那么,应该怎么写,才能把DataRow类型的转换成float类型的呢?
public Ilist(Student) GetAllStudent()
{
IList<Student> alist = new List<Student>();
string sql = "select * from Students";
SqlDataAdapter da = new SqlDataAdapter(sql,DBHelper.Connection);
DataTable dt = new DataTable();
da.Fill(dt);
foreach (DataRow row in dt.Rows)
{
Student stu = new Student();
ar.StudentWeight =float.Parse(row["studentWeight"].ToString());
//上面这句代码一运行就报错:输入字符串不正确
那么,应该怎么写,才能把DataRow类型的转换成float类型的呢?
这样使用string类型显示
float a ((float)(row[ "studentWeight "].ToString()))
你 看看这样可以吧 吧 他的 整体作为一个类型