我正在使用C#和Visual Studio 2005。
void tbb_KeyPress(object sender, KeyPressEventArgs e)
{
if ((Keys)e.KeyChar == Keys.Enter)
{
listBox2.Visible = false;
button4.Visible = false;
if (tbb.Text!="")
{
bb.Visible = true;
bb.Focus();
}
else
{
//tbb.Visible = false;
tbb.Dispose();
bb.Dispose();
textBox2.Visible = true;
textBox2.Focus();
}
}
}
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
if ((Keys)e.KeyChar == Keys.Enter)
{
if (bb.Text == "")
{
MessageBox.Show("Sorry Empty.Row");
this.flowLayoutPanel1.Controls.Clear();
label13.Text = "";
textBox1.Text = "";
textBox2.Text = "";
maskedTextBox1.Text = "";
maskedTextBox1.Enabled = true;
maskedTextBox1.Focus();
textBox1.Enabled = true;
}
else
{
string connstr = "server=.;initial catalog= maa;uid=mah;pwd=mah";
SqlConnection con = new SqlConnection(connstr);
con.Open();
SqlCommand cmd1 = new SqlCommand("insert into debankA(companyID,transID,date,bank,totdepo,narrat) values " +
"(@companyID,@transID,Convert(datetime,'" + maskedTextBox1.Text.ToString() + "',103),@bank,@totdepo,@narrat)", con);
cmd1.Parameters.Add("@bank", SqlDbType.VarChar).Value = textBox1.Text;
cmd1.Parameters.Add("@totdepo", SqlDbType.Decimal).Value = label13.Text;
cmd1.Parameters.Add("@narrat", SqlDbType.VarChar).Value = textBox2.Text;
cmd1.Parameters.Add("@companyID", SqlDbType.Int).Value = label6.Text;
cmd1.Parameters.Add("@transID", SqlDbType.Int).Value = textBox4.Text;
cmd1.ExecuteNonQuery();
string pparticulars = null;
double? depo = null;
string messs = "Record Save Successfully";
foreach (Control ctl in this.flowLayoutPanel1.Controls)
{
if (ctl.Name.Contains("tbb") && ctl is TextBox)
{
pparticulars = ctl.Text;
}
if (ctl.Name.Contains("bb") && ctl is TextBox)
{
double ddepo = 0;
if (double.TryParse(ctl.Text, out ddepo))
depo = ddepo;
if (pparticulars != null && depo != null)
{
SqlCommand cmd = new SqlCommand("insert into debankB(particulars,deposit,companyID,transID)values" +
"(@particulars,@deposit,@companyID,@transID)", con);
cmd.Parameters.Add("@particulars", SqlDbType.VarChar).Value = pparticulars;
cmd.Parameters.Add("@deposit", SqlDbType.Decimal).Value = depo;
cmd.Parameters.Add("@companyID", SqlDbType.Int).Value = label6.Text;
cmd.Parameters.Add("@transID", SqlDbType.Int).Value = textBox4.Text;
cmd.ExecuteNonQuery();
pparticulars = null;
depo = null;
MessageBox.Show(messs);
messs = null;
this.flowLayoutPanel1.Controls.Clear();
label13.Text = "";
textBox1.Text = "";
textBox2.Text = "";
maskedTextBox1.Text = "";
maskedTextBox1.Enabled = true;
maskedTextBox1.Focus();
textBox1.Enabled = true;
}
即使我已经处理了两个空文本框消息始终只显示“空。记录“如上我所说。
这意味着空文本框不会被处理。但如果这是真的,那么当我运行应用程序并创建了文本框,其中的数据是可用的,它保持不变,空文本框是不可见的。按回车键。
我不明白是什么问题。如果文本框在运行时被释放,那么它如何显示为空?