我有一個webform應用程序,它有一個提交按鈕來存儲到sql server。 這裏是它的代碼。Submit button not Firing
try
{
SqlConnection insc = new SqlConnection(@"Data Source=2011-GOA-RCC3\sqlexpress;Initial Catalog=S.I.-DBase-Web;Integrated Security=True");
insc.Open();
SqlCommand cmnd = new SqlCommand();
cmnd.Connection = insc;
cmnd.CommandText = "Insert Into Global_DCR(Sr_No, Comp_ID, Br_Code, Br_Name, Region, Node, Comp_Date, Comp_Time, WAN_IP, Network_Type, Circuit_Type, Ciruit_ID, MLLN_ID, CBS_ATM_TBA, Link_Stat, Call_Cat, Problem_Des, Backup_Work, Status, Resolved_Date, Resolved_Time, Total_Downtime, BSNL_Details, Docket_ID, Action_Owner, Remark) Values(@Sr_No, @Comp_ID, @Br_Code, @Br_Name, @Region, @Node, @Comp_Date, @Comp_Time, @WAN_IP, @Network_Type, @Circuit_Type, @Ciruit_ID, @MLLN_ID, @CBS_ATM_TBA, @Link_Stat, @Call_Cat, @Problem_Des, @Backup_Work, @Status, @Resolved_Date, @Resolved_Time, @Total_Downtime, @BSNL_Details, @Docket_ID, @Action_Owner, @Remark)";
cmnd.Parameters.AddWithValue("@Sr_No", Label2.Text);
cmnd.Parameters.AddWithValue("@Comp_ID", Label4.Text);
cmnd.Parameters.AddWithValue("@Comp_Date", TextBox1.Text);
cmnd.Parameters.AddWithValue("@Comp_Time", TextBox2.Text);
cmnd.Parameters.AddWithValue("@Br_Code", TextBox3.Text);
cmnd.Parameters.AddWithValue("@Br_Name", TextBox4.Text);
cmnd.Parameters.AddWithValue("@Node", TextBox6.Text);
cmnd.Parameters.AddWithValue("@WAN_IP", TextBox7.Text);
cmnd.Parameters.AddWithValue("@Network_Type", DropDownList1.SelectedItem);
cmnd.Parameters.AddWithValue("@Circuit_Type", DropDownList2.SelectedItem);
cmnd.Parameters.AddWithValue("@Circuit_ID", TextBox10.Text);
cmnd.Parameters.AddWithValue("@MLLN_ID", TextBox11.Text);
cmnd.Parameters.AddWithValue("@CBS_ATM_TBA", TextBox12.Text);
cmnd.Parameters.AddWithValue("@Link_Stat", TextBox13.Text);
cmnd.Parameters.AddWithValue("@Call_Cat", TextBox14.Text);
cmnd.Parameters.AddWithValue("@Problem_Des", TextBox15.Text);
cmnd.Parameters.AddWithValue("@Docket_ID", TextBox18.Text);
cmnd.Parameters.AddWithValue("@BSNL_Details", TextBox19.Text);
cmnd.Parameters.AddWithValue("@Action_Owner", TextBox20.Text);
cmnd.Parameters.AddWithValue("@Remarks", TextBox21.Text);
if (Request.Cookies["Region"] != null)
{
TextBox5.Text = Server.HtmlEncode(Request.Cookies["Region"].Value);//read cookie
}
//{
// string a3 = "Not happening Bro1";
// ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + a3 + "');", true);
//}
// button execution breaks at this step. no error is thrown
//to set backup
if (RadioButtonList1.SelectedValue == "Yes")
{
string Yes = "Yes";
cmnd.Parameters.AddWithValue("@Backup_Work", Yes);
}
if (RadioButtonList1.SelectedValue == "No")
{
string No = "No";
cmnd.Parameters.AddWithValue("@Backup_Work", No);
}
//{
// string a2 = "Not happening Bro2";
// ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + a2 + "');", true);
//}
//status
if (RadioButtonList2.SelectedValue == "Resolved")
{
string res = "Resolved";
cmnd.Parameters.AddWithValue("@Status", res);
cmnd.Parameters.AddWithValue("@Resolved_Date", TextBox16.Text);
cmnd.Parameters.AddWithValue("@Resolved_Time", TextBox17.Text);
cmnd.Parameters.AddWithValue("@Total_Downtime", Label25.Text + ":" + Label26.Text + ":" + Label27.Text);//store three values in single table
}
if (RadioButtonList2.SelectedValue == "Pending")
{
string pen = "Pending";
cmnd.Parameters.AddWithValue("@Status", pen);
cmnd.Parameters.AddWithValue("@Resolved_Date", pen);
cmnd.Parameters.AddWithValue("@Resolved_Time", pen);
cmnd.Parameters.AddWithValue("@Total_Downtime", pen);
}
//Session["Comp_ID"] = Label4.Text;
int mn = cmnd.ExecuteNonQuery();
if (mn > 0)
{
string ab = "Incident With Incident ID";
string abc = Convert.ToString(Label4.Text);
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + ab + abc + "');", true);
}
else
{
string sw = "Unable To Create Incident";
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + sw + "');", true);
}
}
catch (Exception s)
{
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + s + "');", true);
}
}
問題是代碼不工作。一旦我填寫頁面上的所有相關數據,並點擊提交按鈕,它不會保存到數據庫。 感謝您的幫助。
你有什麼異常?你能向我們展示relavent aspx代碼嗎? –
Na bro ... 沒有異常拋出.. 它試圖通過插入一些隨機的「消息框」來檢查代碼是否被實際執行。我發現執行非查詢返回零... 但這怎麼可能?我傳遞了所有正確的參數。 –
如果您的'區域'cookie爲'null',則不插入任何默認值。你需要添加其他塊,檢查我的答案。 –