I Have a Problem...
I have a variable on C#, it calls eRFCempresa. This variable gets a data from a xml file, and what I need to do, is:
In SQL Server Management, I want create a Stored Procedure, in this SP, I have to validate if the value stored in eRFCempresa exist in a Table.
Validate a register on SQL Server and C#
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.


Wim SturkenboomRank #2,527 · 554 reputationPosted Oct 2, 2014, 9:51 AM EDT
select * from yourtable where yourcolumn=yourvalue
It's easy to poor this into a stored procedure. Create a new SP, press
Paste above sql query at the right place in the stored procedure. Replace yourvalue above by @p1 (or the sensible name that you gave it) and remove the stuff that you don't want (e.g. p2 and the default select that SSMS puts in there).
The C# part will look like this (I assume that you know how to setup a connection
SqlCommand cmd = new SqlCommand("nameofyoursp", yourConnection);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@p1", yourvaluetocheck);
DataTable tbl = new DataTable();
tbl.Load(cmd.ExecuteReader());
If tbl has one or more rows, yourvalue exists in the table 'yourtable' in the database.