hi friends
i have 5 textboxes(empid,date,intime,outtime,workingtime) and submittbutton
now i enter some integer value in the textboxes
now my query is
empid,date is already entered in database.i dont want enter same empid,date
how can i compared parricular empid,date exist or not.if that empid,date exists it will show error
thanks in advance
saravanan
Loading
PHANI NADIGADDAPosted Feb 2, 2007, 11:59 AM
I would suggest you to return 1 if empid and date are already exists in the database other wise insert your data. .cs code checks the return value with @RETURN_VALUE parameter. if return value is 1 means empid and date are already exists, -1 means not saved because of some problem, other wise data has been saved successfully.
Process goes through like this...
CREATE PROC spInsertData
(
parameters
)
AS
BEGIN
IF EXISTS(SELECT NULL FROM table WHERE empid = @empid AND date = @date)
RETURN '1'
ELSE
INSERT YOUR DATA or what ever you want
IF @@ERROR = 0
RETURN 0
ELSE
RETURN -1
END
------
C# code
--------
public int InsertData(int empid, string date, string intime, string outtime, string workingtime)
{
SqlConnection connection = new SqlConnection("ConnectionString");
connection.Open();
SqlCommand command = new SqlCommand("spInsertData", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@empid", SqlDbType.Int);
command.Parameters.Add("@date", SqlDbType.DateTime);
command.Parameters.Add("@intime", SqlDbType.DateTime);
command.Parameters.Add("@outtime", SqlDbType.DateTime);
command.Parameters.Add("@workingtime", SqlDbType.DateTime);
command.Parameters.Add("@RETURN_VALUE", SqlDbType.Int);
command.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
command.Parameters["@empid"].Value = empid;
command.Parameters["@date"].Value = date;
command.Parameters["@intime"].Value = intime;
command.Parameters["@outtime"].Value = outtime;
command.Parameters["@workingtime"].Value = workingtime;
command.ExecuteNonQuery();
int result = Convert.ToInt32(command.Parameters["@RETURN_VALUE"]);
return result;
}
-----
int result = this.InsertData(passparameters)
if(result == 1)
"Emp ID already exists in the database.";
else if (result == -1)
"Its not been saved because of some problem";
else
"Saved successfully.";
If you have any doubt regarding this! contact me at [email protected].
ALL THE BST.