0
Good Afternoon
I’m new to this c# and SQL but I made an application in c# and I have a Company table that I want to limit to a single record ( a single company) and I want the user to change or delete this record but can not enter any more. The code I made in c#
private bool IfidExists(string EmprId)
{
con.dataGet("Declare @EmprId INT,SELECT @EmprId= COUNT(*) FROM Empresa IF@EmprId>'1'BEGIN ROLLBACK TRANSACTION; RETURN;END ");
DataTable dt = new DataTable();
con.sda.Fill(dt);
if (dt.Rows.Count > 0)
return true;
else
return false;
}
if (Validation())
if (IfidExists(txtEmprId.Text))
{
MessageBox.Show("Só pode Registrar uma empresa");
but won’t let me register any company
I thank you in advance for your help
What, in your model, defines that the company is duplicated? use field to create a unique key. And don’t write your queries that way, it’s best to use the
SqlCommand
– Leandro Angelo
wouldn’t just be doing a
SELECT COUNT(*) FROM Empresa
? to make a simple select no need totransaction
– Ricardo Pontual
Which DB ? Creates the table , inserts a record and creates a Rigger of before Insert or delete giving error in execution , a simple way.
– Motta
Good morning Motta link string is already in the form the Company table is created, the Emprid column which is primary key and autoincrement, can you please give me an example of Trigger?
– Miguel Santos
by "limit an SQL table to a single record" I understand that the table will only have one record is the end point , for which diacho a auto increment key ?! assuming Mysql this post does something similar
– Motta