llqwerasdf 2015-12-24 10:05 采纳率: 0%
浏览 2740

求解答,无效的sql语句,期待delete‘select等

namespace SelectCourse222.CourseManage
{
public partial class AddCourse : Form
{
//string strCon="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Administrator\Desktop\lianglong\db_CourseSelect.accdb";
string strCon = ConfigurationManager.ConnectionStrings["courseselectstring"].ConnectionString;
public AddCourse()
{
InitializeComponent();
}

    private void btnqd_Click_1(object sender, EventArgs e)
    {
        try
        {
            string cmd1 = String.Format("select * from tb_Course where courseId='{0}'", textBox1.Text.Trim());
            if (DBHelper.GetReader(cmd1).HasRows)
            {
                MessageBox.Show("该课程编号已存在,请重新输入!");
                textBox1.Clear();
                textBox1.Focus();
            }
            else
            {
                string cmd = String.Format("insert into tb_Course values('{0}','{1}','{2}')", textBox1.Text.Trim(), textBox4.Text.Trim(), textBox3.Text.Trim());
                if (DBHelper.ExecNoQue(cmd) > 0)
                {
                    MessageBox.Show("课程信息添加成功!");
                    textBox1.Clear();
                    textBox4.Clear();
                    textBox3.Clear();
                    showInfo();
                }
                else
                {
                    MessageBox.Show("课程信息添加失败,请重新输入!");
                }
            }
        }
        catch (Exception er)
        {
            MessageBox.Show(er.Message);
        }
    }

    private void btnqx_Click_1(object sender, EventArgs e)
    {
        this.Close();
    }

    private void AddCourse_Load(object sender, EventArgs e)
    {
        showInfo();
    }
    public void showInfo()
    {


        try
        {
            String dap = string.Format("select * from tb_Course");
            dataGridView1.DataSource = DBHelper.GetReader(dap);
        }
        catch (Exception er)
        {
            MessageBox.Show(er.Message);
        }

    }


    private void btncx_Click(object sender, EventArgs e)
    {
        try
        {
            String adp = string.Format("select * from tb_Course where CourseId='{0}'", texfindcourse.Text.Trim());
            dataGridView1.DataSource = DBHelper.GetTable(adp);
        }
        catch (Exception er)
        {
            MessageBox.Show(er.Message);
        }

    }

    private void btnqb_Click(object sender, EventArgs e)
    {
        showInfo();
    }

    private void btncsc_Click(object sender, EventArgs e)
    {
        try
        {
            string strcmd = String.Format("delete * from tb_Course where courseId='{0}'", textBox2.Text.Trim());
            if (DBHelper.GetReader(strcmd).HasRows)
            {
                MessageBox.Show("课程编号不存在,请重新输入!");
                textBox2.Clear();
                textBox2.Focus();
            }
            else
            {
                MessageBox.Show("删除成功!");
                textBox2.Clear();
                showInfo();
            }
        }
        catch (Exception er)
        {
            MessageBox.Show(er.Message);
        }
    }


}

}

  • 写回答

2条回答 默认 最新

  • devmiao 2015-12-24 15:57
    关注

    检查sql语句,sql语句不对

    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧