我不想只在C#中的文本框中输入空格,而是在空格中输入charector。这是我的错误代码。

编程入门 行业动态 更新时间:2024-10-16 00:21:02
本文介绍了我不想只在C#中的文本框中输入空格,而是在空格中输入charector。这是我的错误代码。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

private void btnsave_Click(object sender,EventArgs e) { if(comboslm.Text ==) { MessageBox.Show(请选择推销员名称); comboslm.Focus(); } 否则if(slmname.Text ==|| slmname.Text ==!char.IsWhiteSpace(e.KeyChar))这里只有红线显示。也无法渲染。) { MessageBox.Show(空的推销员名称不被接受); slmname.Focus(); } else if(combosmancode.Text ==) { MessageBox.Show(Select Record Key Number); combosmancode.Focus(); } else { SqlConnection con = new SqlConnection(@Data Source = M2\SQL2016; Initial Catalog = inventoryDB; Integrated Security = True); con.Open(); SqlCommand cmd = new SqlCommand(UPDATE smanDB SET smaname = @ label2 WHERE smancode = @ label4,con); cmd.Parameters.Add(@ label2,slmname.Text); cmd.Parameters.Add(@ label4,combosmancode.GetItemText(combosmancode.SelectedItem)); cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show(已成功更新); / * combosmancode.SelectedIndex = -1; comboslm.SelectedIndex = -1; slmname.Text =; comboslm.Focus(); * / con = new SqlConnection(@Data Source = M2\SQL2016; Initial Catalog = inventoryDB; Integrated Security = True); con.Open(); string query =SELECT smaname FROM smanDB; string que =SELECT smancode FROM smanDB; SqlDataAdapter da = new SqlDataAdapter(query,con); SqlDataAdapter sda = new SqlDataAdapter(que,con); DataSet ds = new DataSet(); DataSet sds = new DataSet(); da.Fill(ds,smanDB); sda.Fill(sds,smanDB); comboslm.DisplayMember =smaname; comboslm.ValueMember =smaname; comboslm.DataSource = ds.Tables [smanDB]; combosmancode.DisplayMember =smancode; combosmancode.ValueMember =smancode; combosmancode.DataSource = sds.Tables [smanDB]; combosmancode.SelectedIndex = -1; comboslm.SelectedIndex = -1; slmname.Text =; con.Close();

我的尝试: 我试图检查空。我成功了。但是对于空格只有它显示错误。有空格的charector也行。但是只防止显示错误的空格

解决方案

else if (slmname.Text == || slmname .Text ==!char.IsWhiteSpace(e.KeyChar))

该声明的后半部分是错误的。您无法将文本字段( slmname.Text )与布尔值(!char.IsWhiteSpace(e.KeyChar))。

private void btnsave_Click(object sender, EventArgs e) { if(comboslm.Text == "") { MessageBox.Show("Please Select Salesman Name"); comboslm.Focus(); } else if(slmname.Text=="" || slmname.Text==!char.IsWhiteSpace(e.KeyChar)) (Here only redline it is showing.So unable to render also) { MessageBox.Show("Empty Salesman Name Not Accepted"); slmname.Focus(); } else if (combosmancode.Text == "") { MessageBox.Show("Select Record Key Number"); combosmancode.Focus(); } else { SqlConnection con = new SqlConnection(@"Data Source=M2\SQL2016;Initial Catalog=inventoryDB;Integrated Security=True"); con.Open(); SqlCommand cmd = new SqlCommand("UPDATE smanDB SET smaname=@label2 WHERE smancode=@label4", con); cmd.Parameters.Add("@label2", slmname.Text); cmd.Parameters.Add("@label4", combosmancode.GetItemText(combosmancode.SelectedItem)); cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("Updated Successfully"); /* combosmancode.SelectedIndex = -1; comboslm.SelectedIndex = -1; slmname.Text = ""; comboslm.Focus();*/ con = new SqlConnection(@"Data Source=M2\SQL2016;Initial Catalog=inventoryDB;Integrated Security=True"); con.Open(); string query = "SELECT smaname FROM smanDB"; string que = "SELECT smancode FROM smanDB"; SqlDataAdapter da = new SqlDataAdapter(query, con); SqlDataAdapter sda = new SqlDataAdapter(que, con); DataSet ds = new DataSet(); DataSet sds = new DataSet(); da.Fill(ds, "smanDB"); sda.Fill(sds, "smanDB"); comboslm.DisplayMember = "smaname"; comboslm.ValueMember = "smaname"; comboslm.DataSource = ds.Tables["smanDB"]; combosmancode.DisplayMember = "smancode"; combosmancode.ValueMember = "smancode"; combosmancode.DataSource = sds.Tables["smanDB"]; combosmancode.SelectedIndex = -1; comboslm.SelectedIndex = -1; slmname.Text = ""; con.Close();

What I have tried: I tried to check empty. I succeeded. But for spaces only then it showing error. charector with spaces also ok. But prevent only spaces showing error

解决方案

else if(slmname.Text=="" || slmname.Text==!char.IsWhiteSpace(e.KeyChar))

The second half of that statement is wrong. You cannot compare a text field (slmname.Text) to a boolean value (!char.IsWhiteSpace(e.KeyChar)).

更多推荐

我不想只在C#中的文本框中输入空格,而是在空格中输入charector。这是我的错误代码。

本文发布于:2023-11-10 16:28:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1575892.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:空格   这是   是在   我不想   只在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!