未处理的“System.StackOverflowException”类型的异常出现在 System.Windows.Forms.dll 中。
程序如下:
public partial class Form1 : Form
{
private SqlCeConnection cn;
private SqlCeCommand cmd;
int i = 0;
public Form1()
{
InitializeComponent();
this.timer1.Interval = 10000;
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
SqlCeConnection cn = null;
try
{
cn = new SqlCeConnection();
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[2];
this.textBox1.Text = dr[0].ToString();
this.textBox2.Text = dr[1].ToString();
this.textBox3.Text = dr[2].ToString();
}
}
catch (SqlCeException sqlex)
{
foreach (SqlCeError sqlerror in sqlex.Errors)
{ MessageBox.Show(sqlerror.Message); }
}
catch (Exception ex) { MessageBox.Show(ex.Message); }//此处出错:未处理的“System.StackOverflowException”类型的异常出现在 System.Windows.Forms.dll 中。
finally { if (cn.State!= ConnectionState.Closed) { cn.Close(); } }
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“sqlmobileDataSet.学生信息表”中。您可以根据需要移动或移除它。
this.学生信息表TableAdapter.Fill(this.sqlmobileDataSet.学生信息表);
}
}
平台:vs.net 2005、sql ce数据库