我有这个方法:
protected void AddNewCustomer(object sender, EventArgs e)
{
Control control = null;
if (GridView1.FooterRow != null)
{
control = GridView1.FooterRow;
}
else
{
control = GridView1.Controls[0].Controls[0];
}
string SlNo = (control.FindControl("txtSlNo") as TextBox).Text;
string Code = (control.FindControl("txtcode") as TextBox).Text;
string details = (control.FindControl("txtdetails") as TextBox).Text;
using (SqlConnection con = new SqlConnection(""))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "INSERT INTO [Qtattemp] VALUES(@Code,@details,@SlNo)";
cmd.Parameters.AddWithValue("@SlNo", SlNo);
cmd.Parameters.AddWithValue("@Code", Code);
cmd.Parameters.AddWithValue("@details", details);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
Response.Redirect(Request.Url.AbsoluteUri);
}
当我启动程序时,通过
调用此方法public void rc()
{
try{
using (PacketCommunicator communicator = device1.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000))
{
richTextBox1.AppendText("Listening on " + device1.Description + "... \r\n");
// start the capture
communicator.ReceivePackets(0, PacketHandler);
communicator.Break();
}
}
catch (Exception ex)
{
throw ex;
}
}
它在“使用(PacketCommunicator ....”
的行尾)抛出了这个在......
中发生了'System.NullReferenceException'类型的未处理异常附加信息:未将对象引用设置为对象的实例。
添加信息:当我没有方法“rc”和线程,并且代码在构造函数中时,我没有遇到此问题。