注册 登录
编程论坛 C# 论坛

C#窗体应用程序数据写不进assess数据库

djkasopdjopa 发布于 2018-01-19 00:43, 2757 次点击
代码如下    求大神解救
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace zhuce
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            String strConn = "Provider=Microsoft.Jet.OLEDB.12.0;Data Source=Student.mdb";
            OleDbConnection conn = new OleDbConnection(strConn);
            OleDbCommand comm = new OleDbCommand();
            try
            {
                if (textBox1.Text == "")
                    MessageBox.Show("用户名不能为空!");
                else if (textBox2.Text == "")
                    MessageBox.Show("密码不能为空!");
                else if (textBox3.Text != textBox2.Text)
                    MessageBox.Show("两次密码不一致!");
                else if (textBox4.Text == "")
                    MessageBox.Show("地址不能为空!");
                else if (textBox5.Text == "")
                    MessageBox.Show("姓名不能为空!");
                else if (textBox6.Text == "")
                    MessageBox.Show("身份证不能为空!");
                else if (textBox7.Text == "")
                    MessageBox.Show("手机号不能为空!");            
                conn.Open();
                comm.Connection = conn;
                string mdbtr = "INSERT INTO 表1 VALUES('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "')";
               
                comm.ExecuteNonQuery();
                conn.Close();
               
            }

            catch
            {
                MessageBox.Show("注册成功!");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show("注册成功!");
        }
    }
}
2 回复
#2
冰雹小2018-01-22 22:57
回复 楼主 djkasopdjopa
我也是刚学试了一下这句有问题 string mdbtr = "INSERT INTO 表1 VALUES('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "')";却" + textBox3.Text + "
#3
神行2018-03-06 08:44
看一下access有登录账号或密码的吗 连接数据库字符串里
1