使用 OleDbAdapter 删除记录

发布于 2024-12-11 17:27:47 字数 991 浏览 0 评论 0原文

我是 C# 初学者。我正在尝试创建一个网站

,但无法提供删除选项。没有错误显示。但记录没有被删除,

请帮助

protected void delete_button_Click(object sender, EventArgs e) {

        string uname;
        string pwd;

        uname = txt_user.Text;
        pwd = txt_pass.Text;



        string connetionString = null;
        OleDbConnection connection;
        OleDbDataAdapter oledbAdapter = new OleDbDataAdapter();
        string sql = null;
        connetionString = "Provider=SQLOLEDB;dsn=xe;User id=sa;password=password123";
        connection = new OleDbConnection(connetionString);

        sql = "DELETE * FROM Login WHERE username='" + uname + "' and password='" +pwd+ "'";
        try
        {
            connection.Open();
            oledbAdapter.DeleteCommand = connection.CreateCommand();
            oledbAdapter.DeleteCommand.CommandText = sql;

            oledbAdapter.DeleteCommand.ExecuteNonQuery();
            Label4.Text = "deleted";
        }

谢谢

am a beginner in C#. am trying to create a website

i have a problem to give a delete option. there is no error showing. But the recrd is not getting deleted

please help

protected void delete_button_Click(object sender, EventArgs e)
{

        string uname;
        string pwd;

        uname = txt_user.Text;
        pwd = txt_pass.Text;



        string connetionString = null;
        OleDbConnection connection;
        OleDbDataAdapter oledbAdapter = new OleDbDataAdapter();
        string sql = null;
        connetionString = "Provider=SQLOLEDB;dsn=xe;User id=sa;password=password123";
        connection = new OleDbConnection(connetionString);

        sql = "DELETE * FROM Login WHERE username='" + uname + "' and password='" +pwd+ "'";
        try
        {
            connection.Open();
            oledbAdapter.DeleteCommand = connection.CreateCommand();
            oledbAdapter.DeleteCommand.CommandText = sql;

            oledbAdapter.DeleteCommand.ExecuteNonQuery();
            Label4.Text = "deleted";
        }

thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夕嗳→ 2024-12-18 17:27:47

sql 应从

"DELETE FROM Login WHERE username='" + uname + "' and password='" +pwd+ "'"

SQL 中删除 *。

The sql should be

"DELETE FROM Login WHERE username='" + uname + "' and password='" +pwd+ "'"

Remove * from the SQL.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文