c# vs2008 报错未将对象引用设置到对象的实例

Wendy_forget 2014-07-26 11:49:54
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]);
}

}
}

程序报错:未将对象引用设置到对象的实例

...全文
121 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
欢乐的小猪 2014-07-26
  • 打赏
  • 举报
回复
有变量没初始化。。调试运行看下吧
exception92 2014-07-26
  • 打赏
  • 举报
回复
这种问题 ,你应该自己加个 断电 调试一下。
Wendy_forget 2014-07-26
  • 打赏
  • 举报
回复
新手求大神解答,哪段代码有错!!
柏澄君 2014-07-26
  • 打赏
  • 举报
回复
就是有变量为空,实例化一下 或者确保变量不为空

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧