Last post Dec 03, 2008 09:06 AM by raghav_khunger
Dec 02, 2008 06:24 AM|ankitsahu|LINK
hi all ,
i have 3 dropdown and 1txtbox. all dropdown are bind by db on calling 1 to another.and write in txtbox.
my problem is when i insert value in txtbox and inserting in db it should not be inserted if any value is already fill for appropriate selected dropdown.and to give error msg. for example if in 3 dropdown value is
DDa ,DDb ,DDc and txtvalue is abc is already in db so
DDa ,DDb ,DDc and txtvalue is xyz should not be inderted in db.
combination of the 3 fields must be unique.
Dec 02, 2008 07:18 AM|imran_khan|LINK
there is nothing to do with asp.net. You need to change your sql query or store procedure.
Give condition before inserting data into database.
If not exists(Select * from yourTableName where Field1=DDL1Value and Field2=DDL2Value and Field3=DDL3Value)
//Insert Query here
Now,If your executeNonQuery return 1 then your data is inserted otherwise not.
Dec 02, 2008 07:32 AM|raghav_khunger|LINK
In sql u can write like this
ie if duplicate record is going inside as per ur case Error message is raised
Now In front end u can get that error in ur catch block and can display in label
ie in aspx.cs
lblError.Text = ex.Message.ToString();
PLZ MARK AS ANSWER IF IT HELP U.
Dec 03, 2008 08:53 AM|ankitsahu|LINK
now its my sp which working fine but i dont know how to take exception from sql and display in page
this is my try and catch block tell me more about that.
bytheway thanx ragav for above sp as u give but plz tell me more about catch section or link any
Dec 03, 2008 09:06 AM|raghav_khunger|LINK
As i Specified
Take A label On Aspx Page with Id That I have Taken lblError
And Then In The Catch Block Write Like this
I have Used two catch block
Now When The Error comes From Sql then first block will foolowd and message will be displayed on Lable
And when exception occurs at front end side then Second catch block will follow