程序如下:public partial class Form1 : Form
{
private SqlCeConnection cn;
private SqlCeCommand cmd;
int i = 0;
public Form1()
{
InitializeComponent();
this.timer1.Interval = 1000;
timer1.Enabled = true;
} private void timer1_Tick(object sender, EventArgs e)
{
SqlCeConnection cn = null; try
{
cn.ConnectionString = @"Data Source =F:\database\database\sqlmobile.sdf;";
cn.Open();
SqlCeCommand cmd = cn.CreateCommand();
cmd.CommandText = "学生信息表";
cmd.CommandType = CommandType.TableDirect;
SqlCeDataAdapter da = new SqlCeDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "学生信息表");
i++;
Console.WriteLine("{0}",i);
while (i<3)
{
DataRow dr = ds.Tables["学生信息表"].Rows[i];
this.textBox1.Text = dr[0].ToString();
this.textBox2.Text = dr[1].ToString();
this.textBox3.Text = dr[2].ToString();
timer1.Enabled = false;
}
}
catch (SqlCeException sqlex)
{
foreach (SqlCeError sqlerror in sqlex.Errors)
{ MessageBox.Show(sqlerror.Message); }
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
finally { if (cn.State!= ConnectionState.Closed) { cn.Close(); } }//此处出错:未处理NullReferenceException
} private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“sqlmobileDataSet.学生信息表”中。您可以根据需要移动或移除它。
this.学生信息表TableAdapter.Fill(this.sqlmobileDataSet.学生信息表); }
} 平台是:vs.net2005、sql ce数据库
{
private SqlCeConnection cn;
private SqlCeCommand cmd;
int i = 0;
public Form1()
{
InitializeComponent();
this.timer1.Interval = 1000;
timer1.Enabled = true;
} private void timer1_Tick(object sender, EventArgs e)
{
SqlCeConnection cn = null; try
{
cn.ConnectionString = @"Data Source =F:\database\database\sqlmobile.sdf;";
cn.Open();
SqlCeCommand cmd = cn.CreateCommand();
cmd.CommandText = "学生信息表";
cmd.CommandType = CommandType.TableDirect;
SqlCeDataAdapter da = new SqlCeDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "学生信息表");
i++;
Console.WriteLine("{0}",i);
while (i<3)
{
DataRow dr = ds.Tables["学生信息表"].Rows[i];
this.textBox1.Text = dr[0].ToString();
this.textBox2.Text = dr[1].ToString();
this.textBox3.Text = dr[2].ToString();
timer1.Enabled = false;
}
}
catch (SqlCeException sqlex)
{
foreach (SqlCeError sqlerror in sqlex.Errors)
{ MessageBox.Show(sqlerror.Message); }
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
finally { if (cn.State!= ConnectionState.Closed) { cn.Close(); } }//此处出错:未处理NullReferenceException
} private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“sqlmobileDataSet.学生信息表”中。您可以根据需要移动或移除它。
this.学生信息表TableAdapter.Fill(this.sqlmobileDataSet.学生信息表); }
} 平台是:vs.net2005、sql ce数据库
解决方案 »
- WinForm 如果获取当前IE程序中的地址栏中的URL地址。
- 关于C#调用第三方VC编写的DLL
- 项目从VS2003升VS2008的问题,请帮忙看看!
- winform datagrid 列名为什么不能上下移动
- C#编码标准 指导和最佳实践 技术专家的评析
- 我现在要在vs2008里做一个用户可以直接操作excel的功能,用VSTO能实现吗?
- 做信息管理的程序员,你的前途(钱图)在那里?终极迷茫?
- C#DLL数据相关
- 如何用C#注冊系統熱鍵﹖
- 有话要说的朋友请近来(班门斧请注意)
- DataGridTextBoxColumn Format问题,急急急急!!!!在线等
- C#出力excel,开发是用的office2003,在office2000上出错,如何解决?
删除了看看
而且 你的i 一开始为0,走到循环中 timer就停用了,应该也有问题
try
{
cn = new SqlConnection(); // 必须先创建对象
cn.ConnectionString = @"Data Source =F:\database\database\sqlmobile.sdf;";
cn.Open();
//
}
catch
{
}