Hier ist meine Tabellen, ich kann Anzeige, Soyad und E-Mail aktualisieren, aber wenn ich versuche, Telefon zu aktualisieren es mit dem Fremdschlüssel [UserFk] kollidiert, habe ich bereits Fremdschlüssel Update auf Kaskade so, ich kann das Problem hier nicht herausfinden. Danke im VorausUpdate-Anweisung im Konflikt mit Fremdschlüssel
CREATE TABLE [dbo].[ogrenci] (
[ogrenciNo] INT NOT NULL,
[ad] NVARCHAR (20) NOT NULL,
[soyad] NVARCHAR (20) NOT NULL,
[email] NVARCHAR (50) NOT NULL,
[fakulte_no] INT NOT NULL,
[bolum_ad] NVARCHAR (30) NOT NULL,
[bolum_no] INT DEFAULT ((1)) NOT NULL,
[telefon] NVARCHAR (50) DEFAULT ((1)) NOT NULL,
PRIMARY KEY CLUSTERED ([ogrenciNo] ASC),
UNIQUE NONCLUSTERED ([ogrenciNo] ASC),
UNIQUE NONCLUSTERED ([email] ASC),
CONSTRAINT [bolumFk] FOREIGN KEY ([bolum_no]) REFERENCES [dbo].[bolum] ([bolumNo]) ON DELETE CASCADE,
CONSTRAINT [fakulteFk1] FOREIGN KEY ([fakulte_no]) REFERENCES [dbo].[fakulte] ([fakulteId]) ON DELETE CASCADE,
CONSTRAINT [userFk] FOREIGN KEY ([telefon]) REFERENCES [dbo].[loginusers] ([upassword]) ON DELETE CASCADE ON UPDATE CASCADE
);
und die zweite,
CREATE TABLE [dbo].[loginusers] (
[username] NVARCHAR (50) NOT NULL,
[upassword] NVARCHAR (50) NOT NULL,
PRIMARY KEY CLUSTERED ([upassword] ASC)
);
und hier ist die Update-Button,
private void btnUpdate_Click(object sender, EventArgs e)
{
try
{
if (txtOgrenciNo.Text.Length != 0 && txtAd.Text.Length != 0 && txtSoyad.Text.Length != 0 && txtEmail.Text.Length != 0 && txtTelefon.Text.Length != 0)
{
string query = "UPDATE ogrenci SET [email protected],[email protected],[email protected],[email protected],[email protected] WHERE [email protected]";
string query1 = "UPDATE loginusers SET [email protected],[email protected] WHERE [email protected]";
using (connection = new SqlConnection(connectionString))
using (SqlCommand command = new SqlCommand(query, connection))
using (SqlCommand cmd = new SqlCommand(query1, connection))
{
connection.Open();
command.Parameters.AddWithValue("@ogrenciNoVal", txtOgrenciNo.Text);
command.Parameters.AddWithValue("@adVal", txtAd.Text);
command.Parameters.AddWithValue("@soyadVal", txtSoyad.Text);
command.Parameters.AddWithValue("@emailVal", txtEmail.Text);
command.Parameters.AddWithValue("@telefonVal", txtTelefon.Text);
cmd.Parameters.AddWithValue("@emailVal", txtEmail.Text);
cmd.Parameters.AddWithValue("@telefonVal", txtTelefon.Text);
command.ExecuteNonQuery();
cmd.ExecuteNonQuery();
gridDoldur();
}
}
else
{
MessageBox.Show("Öğrenci bilgileri boş girilemez.", "Bilgilendirme", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Ich denke, Sie haben einen logischen Fehler, in Ihrer 'loginusers' Tabelle primarykey ist' upassword', kann es verschiedene Benutzer mit dem gleichen Passwort, habe ich Recht? –
gut in loginusers Tabelle Ich habe die Benutzer Telefonnummer ist eigentlich das userpassword, so dass jeder unterschiedliche phonenumbers hat, können keine verschiedenen Benutzer nicht haben gleiche Pass. –
Ok ich habe es, ich werde die Antwort posten –