0
我有一個列表框,其中包含一些實體,我需要選擇它才能使提交按鈕成功工作,但是當沒有選擇實體時它應該給出錯誤 i是新的嘗試捕捉誰能幫我在哪裏代碼 這裏適用嘗試捕捉的代碼是在asp.net中使用try語句使用if語句
protected void SubmitBtn_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["cn"].ConnectionString;
business.clsprofiles obj1 = new business.clsprofiles();
business.clsprofilesprp objprp1 = new business.clsprofilesprp();
objprp1.id = Convert.ToInt32(Session["cod"]);
objprp1.name = TextBox1.Text;
objprp1.password = TextBox2.Text;
objprp1.description = TextBox3.Text;
objprp1.modified = DateTime.Now;
obj1.upd_profiles(objprp1);
//
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd = new SqlCommand("select id from profiles_plugins where profile_id=" + Convert.ToInt32(Session["cod"]), con);
SqlDataReader dr = cmd.ExecuteReader();
var yourlist = new List<Int32>();
if (dr.HasRows)
{
while (dr.Read())
{
yourlist.Add(Convert.ToInt32(dr[0]));
}
}
dr.Close();
cmd.Dispose();
con.Close();
//
Array k = yourlist.ToArray();
//
business.clsprofiles_plugins obj2 = new business.clsprofiles_plugins();
business.clsprofiles_pluginsprp objprp2 = new business.clsprofiles_pluginsprp();
for (Int32 i = 0; i < k.Length; i++)
{
objprp2.id = Convert.ToInt32(k.GetValue(i));
obj2.del_profiles_plugins(objprp2);
}
for (Int32 i = 0; i < ListBox1.Items.Count; i++)
{
if (ListBox1.Items[i].Selected)
{
objprp2.profile_id = Convert.ToInt32(Session["cod"]);
objprp2.plugin_id = Convert.ToInt32(ListBox1.Items[i].Value);
obj2.sav_profiles_plugins(objprp2);
}
}
Response.Redirect("myprofile.aspx");
}
請與您所使用的語言標記您的問題。沒有人熱切地等待標籤爲try-catch的新問題,但許多專家正在用一種他們擅長的語言來標註新問題。 – 2011-01-26 10:30:30