qq_27602361 2015-04-24 06:17 采纳率: 61.5%
浏览 1613

数据库中主键信息存在,注册信息中主键信息重复问题

public partial class 挂号界面 : Form
{
       OleDbConnection con = new OleDbConnection();
       string str = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\hospital\data.accdb";

    public 挂号界面()
    {
        InitializeComponent();
        con.ConnectionString = str;

    }

    private void Form2_Load(object sender, EventArgs e)
    {

    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {

    }

    private void textBox2_TextChanged(object sender, EventArgs e)
    {

    }

    private void textBox3_TextChanged(object sender, EventArgs e)
    {

    }

    private void textBox4_TextChanged(object sender, EventArgs e)
    {

    }

    private void button1_Click(object sender, EventArgs e)
    {
        string a = textBox1.Text;
        string b = textBox2.Text;
        string c = textBox3.Text;
        string d = textBox4.Text;
       OleDbCommand cmd = new OleDbCommand(@"insert into [patient](ID,姓名,年龄,性别) values(" + a + ",'" + b + "'," + c + ",'" + d + "')");
       con.Open();
        cmd.Connection = con;
        cmd.ExecuteNonQuery();
        con.Close();


            MessageBox.Show("挂号成功!");

    }

    private void button2_Click(object sender, EventArgs e)
    {
        textBox1.Text = "";
        textBox2.Text = "";
        textBox3.Text = "";
        textBox4.Text = "";

    }

    private void button3_Click(object sender, EventArgs e)
    {
        this.Hide();
        new 挂号缴费界面().ShowDialog();
    }
}

}
求注册的信息中ID在数据库中已经存在,提示ID存在的代码 ,并告知添加在何处

  • 写回答

4条回答 默认 最新

  • bdmh 移动开发领域优质创作者 2015-04-24 06:32
    关注

    你可以自己sql查一遍,返回数据如果不为空,表示存在,你自己提示

    评论

报告相同问题?

悬赏问题

  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?