我有一个带有表安全性的数据库和2个字段用户名和密码,其中包含几个我要删除的重复数据在C#.net中复制我将使用的SQL语句是什么。在更新期间出现重复的用户名和密码来自另一个文件的数据库文件。或者如何仅复制数据库基本文件中不存在的记录。我需要在CSharp.net这里做它代码的一部分,我想删除数据。 请帮助
private void ReadUFbtn_Click(object sender, EventArgs e)
{ //new data in desktop so it comes as Source so main becomes as backup
// backup is main so here is mail pis in opened
string targetPath = @"C:\Users\User\Desktop\Prashant\";
string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\PIS.mdb;Jet OLEDB:Database Password=Prashant;";
Con = new OleDbConnection(@constr);
Con.Open();
Com = new OleDbCommand();
Com.Connection = Con;
try
{
if (!System.IO.Directory.Exists(targetPath))
{
DialogResult X = MessageBox.Show("The Direcory / 5File Dose not exits", "PIS System");
}
else
{
//backup open
if (Con.State == ConnectionState.Closed)
Con.Open();
//target //main //backup //source from data //desktop
//backup // main data
string selQuery = "INSERT INTO Security SELECT DISTINCT * FROM [MS Access;DATABASE=c:\\Users\\User\\Desktop\\Prashant\\PIS.mdb;PWD=Prashant;].[Security]";
Com.CommandText = selQuery;
Com.CommandType = CommandType.Text;
Com.Connection = Con;
MessageBox.Show("File Updated");
Com.CommandText = "SELECT DISTINCT * FROM Security ";
int result = Com.ExecuteNonQuery();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
答案 0 :(得分:0)
执行类似的操作应删除MS-Access中的重复记录
delete from Security
where id not in
(select min(id) from Security T2
where T2.username=Security.username and T2.password=Security.password)