珊阡陌提 2021-06-09 18:07 采纳率: 28.6%
浏览 25
已结题

若输入的用户名在表格中存在,则将表格中的光标指针指向所输入的用户名记录行中

try
            {

                if (textBox6.Text == "")
                {
                    MessageBox.Show("用户名不允许为空,并返回重输");
                    textBox6.Focus();
                    return;
                }
                con.Open();
                com.Connection = con;
                com.CommandText = String.Format("select count(*) from users where username='{0}'", textBox6.Text);
                int a = (int)com.ExecuteScalar();

                if (a != 0)
                {
                    com.CommandText = String.Format("select username from users where username = '{0}'",textBox6.Text);
                    com.ExecuteScalar();
                  
                    dgvRes.CurrentCell = dgvRes.Rows[r].Cells[0];
                    


                }
                else
                {
                    MessageBox.Show("输入的用户名不存在,请重新输入!");
                    textBox6.Focus();
                }

            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 已结题 (查看结题原因) 8月16日