【发布时间】:2014-03-14 07:28:09
【问题描述】:
我这里有一个代码,用于计算每月打印的页数:
public void OnDataReceived(IAsyncResult asyn)
{
try
{
CSocketPacket theSockId = (CSocketPacket)asyn.AsyncState ;//creating object of the class
//end receive of data
int iReceive = 0 ;
iReceive = theSockId.thisSocket.EndReceive (asyn);
char[] chars = new char[iReceive + 1];
System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder(); //creating object for decoding
int charLen = d.GetChars(theSockId.dataBuffer, 0, iReceive, chars, 0);
System.String szData = new System.String(chars);
string test = count_page.Text + szData;
string count_pages = Regex.Replace(test, "[^.0-9]", "");
count_page.Text = count_pages;
dbConnect.Update(count_pages); //problem lines
//as data arrives the bytes are appended to the existing string printer throws data in an ASCII format 1 byte at a time
WaitForData();
}
catch (ObjectDisposedException )
{
System.Diagnostics.Debugger.Log(0,"1","\nOnDataReceived: Socket has been closed\n");
}
catch(SocketException se)
{
MessageBox.Show (se.Message ); //gives an error message if any exception has occured
}
}
如果我没有将我注释的行作为问题行放在上面,则此代码可以正常工作:
dbConnect.Update(count_pages);
但我希望它在数据库中更新,所以我将计数页的值传递给类 dbConnect.Update。但是,当我添加这一行时。 count_pages 的值似乎不再显示在文本框中,并且它也没有将值传递给数据库无法更新的 dbConnect.Update 类。有谁知道为什么会这样?
【问题讨论】:
-
消息框停止您的方法。你根本不能那样使用它。
-
真的吗?对不起,我是新手。我实际上只是想测试它,因为我想将值传递给数据库类,例如 updateDB(count_pages)。但似乎该值变为空。知道为什么吗?