求解答,无效的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个回答

检查sql语句,sql语句不对

llqwerasdf
llqwerasdf 看不出来啊,求解答啊
接近 5 年之前 回复

可以把sql打印出来看一下,是不是你想要的语句

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐