c# vs2008 报错未将对象引用设置到对象的实例
record.cs
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SQLite;
namespace WindowsFormstest
{
class record
{
private int SN;
private int TASK;
private float MOVE;
private float TURN;
private float[] TEMP;
private float QUAKE;
public int sn
{
get { return SN;}
set { SN = value; }
}
public int task
{
get { return TASK;}
set { TASK = value; }
}
public float move
{
get { return MOVE; }
set { MOVE = value; }
}
public float turn
{
get { return TURN; }
set { TURN = value; }
}
public float[] temp{get;set;}
public float quake
{
get { return QUAKE; }
set { QUAKE = value; }
}
}
}
recordDAL.cs
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SQLite;
namespace WindowsFormstest
{
class recordDAL
{
private const string sconn="F:/Grade 1 master/study/WindowsFormstest/WindowsFormstest/data/20130512230545.db;Version=3;";
//查询温度记录
public static record Gettemp()
{
try
{
using (SQLiteConnection conn = new SQLiteConnection(sconn))
{
conn.Open();
SQLiteCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT temp FROM record_run ;";
//cmd.Parameters.Add(new SQLiteParameter("task", task));
SQLiteDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
record RECORD = new record();
int i=0;
do
{
i++;
RECORD.temp[i] = dr.GetFloat(i);
}
while (dr.GetFloat(i)!= 0);
return RECORD;
}
else
return null;
}
}
catch (Exception)
{
//Do any logging operation here if necessary
return null;
}
}
}
}
主界面:
代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormstest
{
public partial class chart : Form
{
public chart()
{
InitializeComponent();
}
//private const string sConn = "F:/Grade 1 master/study/WindowsFormstest/WindowsFormstest/data/20130512230545.db;Version=3;";
private void btntemp_Click(object sender, EventArgs e)
{
//显示温度
record RECORD = new record();
RECORD = recordDAL.Gettemp();
Console.WriteLine(RECORD.temp[0]);
}
}
}
程序报错:未将对象引用设置到对象的实例