我正在寻找一种UPDATE
来自C code-behind
的{{1}} SQL服务器数据库session parameter
的方法,这就是我的SqlCommand
在 ASP:
重要提示: C#中的SqlCommand
将在static function
中,是否会出现问题?
提前致谢!
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SPMS_DBConnectionString1 %>"
UpdateCommand="UPDATE Project SET startDate = @startDate, dueDate = @dueDate, progress = @progress, status = @status WHERE (prID = @prID)">
<UpdateParameters>
<asp:SessionParameter Name="prID" SessionField="project" Type="String" />
<asp:Parameter Name="startDate" Type="DateTime"/>
<asp:Parameter Name="dueDate" Type="DateTime" />
<asp:Parameter Name="progress" Type="Int32" />
<asp:Parameter Name="status" Type="Boolean" />
<asp:Parameter Name="projectID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
答案 0 :(得分:0)
这就是我解决它的方法:
string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["SPMS_DBConnectionString1"].ConnectionString;
using (SqlConnection connection = new SqlConnection(connectionString))
using (SqlCommand command = connection.CreateCommand())
{
DateTime startDate = DateFromMiliSec(start);
DateTime dueDate = DateFromMiliSec(end);
int progress = Convert.ToInt32(prog);
string prID = HttpContext.Current.Session["project"].ToString();
command.CommandText ="UPDATE Project SET startDate = @startDate, dueDate = @dueDate, progress = @progress, status = @status WHERE (prID = @prID)";
command.Parameters.AddWithValue("@startDate", startDate );
command.Parameters.AddWithValue("@dueDate", dueDate );
command.Parameters.AddWithValue("@progress", progress );
command.Parameters.AddWithValue("@status", status );
command.Parameters.AddWithValue("@prID", prID );
connection.Open();
command.ExecuteNonQuery();
connection.Close();
}