使用 OleDbAdapter 删除记录
我是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
sql 应从
SQL 中删除 *。
The sql should be
Remove * from the SQL.