try
{
// Problematic code goes here (i.e. opening a file, connecting to a database).
}
catch
{
// An error has been detected. You can deal with it here.
}
finally
{
// Clean up code here, regardless of whether or not there is an error
}
for example
if (IsPostBack == false)
{
try
{
SqlConnection con = new SqlConnection(Data.connect);
SqlDataAdapter da = new SqlDataAdapter("select * from StudI", con);
SqlCommandBuilder cm = new SqlCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds, "Stud_Info");
if (ds.Tables["Stud_Info"].Rows.Count > 0)
{
GridView1.DataSource = ds.Tables["Stud_Info"];
GridView1.DataBind();
}
}
catch(Exception ex)
{
ClientScript.RegisterClientScriptBlock(GetType(), "Javascript", "<script>alert(' " + ex.Message.ToString() + "')</script>");
}
}
0 comments:
Post a Comment