我是ASP.NET新手,搜索每一個表單,但找不到更好的解決方案。我正在執行使用以下代碼的過程,但沒有成功:如何在ASP.NET中爲SelectedIndex值執行存儲過程?
我需要爲存儲過程提供月份和年份值而不是SelectedIndex。
Thanx提前。
protected void Page_Load(object sender, EventArgs e)
{
var months = System.Globalization.DateTimeFormatInfo.InvariantInfo.MonthNames;
slMonth.DataSource = months;
slMonth.DataBind();
ListItem li = new ListItem();
li.Text = "-Select Month-";
li.Value = "-1";
slMonth.Items.Insert(0, li);
slMonth.SelectedIndex = 0;
slYear.Items.Insert(0, "-Select Year-");
int index = 1;
for (int Year = 2000; Year <= DateTime.Now.Year; Year++)
{
ListItem liYear = new ListItem(Year.ToString(), Year.ToString());
slYear.Items.Insert(index, liYear);
index++;
}
}
protected void Update_Spend(object sender, System.EventArgs e)
{
SqlConnection SQLConn = new SqlConnection (@"Data Source=RFMMailServ;Database=Acquiring;User Id=sa;[email protected]+;");
SqlCommand cmdUpdate = new SqlCommand("UpdatetblRPT_Spend", SQLConn);
cmdUpdate.CommandType = CommandType.StoredProcedure;
cmdUpdate.Parameters.Add("@Month", SqlDbType.Int).Value = slMonth.SelectedIndex;
cmdUpdate.Parameters.Add("@Year", SqlDbType.VarChar).Value = slYear.SelectedIndex;
SQLConn.Open();
cmdUpdate.ExecuteNonQuery();
LastMsg.Text = "Spend updated successfully.";
}
_no success_是什麼意思?你得到任何異常或錯誤信息? –