i am writing Data Base Connectivity method in WCF in which i am cheacking if data exist then It should check that data in in Database or not else insert data in Database.
now if there is already Data inside the data base how can i send msg to client that data is already there.
here is my Wcf code...
public void Insert(string value, string value1, string value2)
{
string select = "Select count(*) from Test where FName = '" + value1 + "' ";
SqLite_con = new SQLiteConnection(@"data source=E:\WCF.s3db;Version=3;New=False;Compress=True;");
SqLite_con.Open();
Sqlite_cmd = new SQLiteCommand(select, SqLite_con);
int count = Convert.ToInt32(Sqlite_cmd.ExecuteScalar());
SqLite_con.Close();
if (count > 0)
{
/// here if data is exist i want to send msg
}
else
{
string Insert = "Insert into RackSpaceDownload (FName,Source_path,Destination_path,Last_modified_date) values ('" + value1 + "','" + SourcePath + "','" + value2 + "','" + FileDate + "')";
SqLite_con = new SQLiteConnection(@"data source=E:\WCF.s3db;Version=3;New=False;Compress=True;");
SqLite_con.Open();
Sqlite_cmd = SqLite_con.CreateCommand();
Sqlite_cmd.CommandText = Insert;
Sqlite_cmd.ExecuteNonQuery();
SqLite_con.Close();
}
}
}
SenthilkumarPosted Apr 12, 2012, 6:45 AM
You need to throw the message so that the client can catch and show it.
throw new Exception("Custom Exception");
Usually what they used to do, they will create the fault contract in WCF with custom data contract.
For more info:
http://www.codeproject.com/Articles/294609/Uing-FaultContract-to-throw-custom-error-informati
Sumit KumawatPosted Apr 12, 2012, 6:49 AM