here when select same date , same batch should give me alert message pop-up. tried try
catch
method it's not working.tell me went wrong.
my code far
using (sqlconnection con2 = new sqlconnection(configurationmanager.connectionstrings["connectionstring"].connectionstring)) { var fromdate = datetime.parse(txtfromdate.text); var todate = datetime.parse(txttodate.text); var datedif1 = (todate - fromdate).days; var sqlinsert = new sqlcommand("insert datelist ([datedif],[batch],[daywk],[semester],[weekbatch],[subject],[facultyname],[facultyid],[weekmonth]) select * (select @datedif datedif, @batch batch,@daywk daywk,@semester semster,@weekbatch weekbatch,@subject subject,@facultyname facultyname,@facultyid facultyid,@weekmonth weekmonth) temp not exists (select datedif,batch datelist batch=@batch , datedif=@datedif)", con2); var sqlparamater = sqlinsert.parameters.add("@datedif", sqldbtype.date); var sqlparameter1 = sqlinsert.parameters.add("@batch", sqldbtype.nvarchar); var sqlparameter2 = sqlinsert.parameters.add("@daywk", sqldbtype.nvarchar); var sqlparameter3 = sqlinsert.parameters.add("@semester", sqldbtype.nvarchar); var sqlparameter4 = sqlinsert.parameters.add("@weekbatch", sqldbtype.nvarchar); var sqlparameter5 = sqlinsert.parameters.add("@subject", sqldbtype.nvarchar); var sqlparameter6 = sqlinsert.parameters.add("@facultyname", sqldbtype.nvarchar); var sqlparameter7 = sqlinsert.parameters.add("@facultyid", sqldbtype.nvarchar); var sqlparameter8 = sqlinsert.parameters.add("@weekmonth", sqldbtype.nvarchar); con2.open(); try { (var = 0; <= datedif1; i++) { var consecutivedate = fromdate.adddays(i); sqlparamater.value = consecutivedate; sqlparameter1.value = batch1; sqlparameter2.value = dayweek; sqlparameter3.value = semester; sqlparameter4.value = weekbatch; sqlparameter5.value = subject; sqlparameter6.value = faculty; sqlparameter7.value = facultyid; sqlparameter8.value = weekmonth; int s = sqlinsert.executenonquery(); } } catch { response.write("<script>alert('already date selected.select date')</script>"); con2.close(); } } }
1 - please first check going inside catch block put debugger there.
2 - put debugger on page load check when happening.
you can use registerstartupscript() method
at server side
catch { string msg="already date selected.select date"; scriptmanager.registerstartupscript(this, gettype(), "myfunction", "myfunction('"+msg+"');", true); }
at client side
<script> function myfunction(a) { alert(a); } </script>
also better make store procedure.
Comments
Post a Comment