每当我执行下面的代码时,第二个@OrderNo上的sql参数出现错误
protected void lvProjects_ItemCommand(object sender, ListViewCommandEventArgs e)
{
Literal ltOrderNo = (Literal)e.Item.FindControl("ltOrderNo");
if (e.CommandName == "startproj")
{
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "UPDATE Project " +
"SET Status='On Going' , StartDate=@StartDate WHERE OrderNo=@OrderNo";
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@OrderNo", ltOrderNo.Text);
cmd.Parameters.AddWithValue("@StartDate", DateTime.Now);
cmd.ExecuteNonQuery();
con.Close();
Response.Redirect("Default.aspx");
}
if (e.CommandName == "endproj")
{
#region
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "UPDATE Project " +
"SET Status='Finished' , EndDate=@EndDate WHERE OrderNo=@OrderNo";
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@OrderNo", ltOrderNo.Text);
cmd.Parameters.AddWithValue("@EndDate", DateTime.Now);
cmd.ExecuteNonQuery();
con.Close();
#endregion
#region
con.Open();
cmd.CommandText = "INSERT INTO Deliveries VALUES (@OrderNo, @Status)";
cmd.Parameters.AddWithValue("@OrderNo", ltOrderNo.Text);
cmd.Parameters.AddWithValue("@Status", "Pending");
cmd.ExecuteNonQuery();
con.Close();
#endregion
}
}
答案 0 :(得分:0)
尝试创建第二个if (e.CommandName == "endproj")
{
#region
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "UPDATE Project " +
"SET Status='Finished' , EndDate=@EndDate WHERE OrderNo=@OrderNo";
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@OrderNo", ltOrderNo.Text);
cmd.Parameters.AddWithValue("@EndDate", DateTime.Now);
cmd.ExecuteNonQuery();
cmd.Dispose();
con.Close();
#endregion
#region
con.Open();
SqlCommand cmd1 = new SqlCommand();
cmd1.CommandText = "INSERT INTO Deliveries VALUES (@OrderNo, @Status)";
cmd1.Parameters.AddWithValue("@OrderNo", ltOrderNo.Text);
cmd1.Parameters.AddWithValue("@Status", "Pending");
cmd1.ExecuteNonQuery();
cmd1.Dispose();
con.Close();
#endregion
}
作为新的<b:if cond='data:blog.pageType == "index"'>
<b:if cond='data:post.thumbnailUrl'>
<div class='block-image'><div class='thumb'>
<a href='<data:post.url/>' style='background:url(<data:post.thumbnailUrl/>) no-repeat center center;background-size:cover'></a>
</div>
</div>
<b:else/>
<b:if cond='data:post.firstImageUrl'>
<div class='block-image'><div class='thumb'>
<a href='<data:post.url/>' style='background:url(<data:post.firstImageUrl/>) no-repeat center center;background-size:cover'></a>
</div>
</div>
<b:else/>
<div class='block-image'><div class='thumb'>
<a href='<data:post.url/>' style='background:url(http://1.bp.blogspot.com/-eAeO-DYJDws/Vkqtj4HFBFI/AAAAAAAAB0o/Q5OLsyONXM0/s1600-r/nth.png) no-repeat center center;background-size:cover'></a>
</div>
</div>
</b:if></b:if>
</b:if>
<b:if cond='data:blog.pageType == "archive"'>
<b:if cond='data:post.thumbnailUrl'>
<div class='block-image'><div class='thumb'>
<a href='<data:post.url/>' style='background:url(<data:post.thumbnailUrl/>) no-repeat center center;background-size:cover'></a>
</div>
</div>
<b:else/>
<b:if cond='data:post.firstImageUrl'>
<div class='block-image'><div class='thumb'>
<a href='<data:post.url/>' style='background:url(<data:post.firstImageUrl/>) no-repeat center center;background-size:cover'></a>
</div>
</div>
<b:else/>
<div class='block-image'><div class='thumb'>
<a href='<data:post.url/>' style='background:url(http://1.bp.blogspot.com/-eAeO-DYJDws/Vkqtj4HFBFI/AAAAAAAAB0o/Q5OLsyONXM0/s1600-r/nth.png) no-repeat center center;background-size:cover'></a>
</div>
</div>
</b:if></b:if>
</b:if>
而不是尝试使用第一个。{/ p>
cordova platform update ios
答案 1 :(得分:0)
您正在重用{{1}} SqlCommand对象,在第二个if语句中,您添加了两次名为OrderNo的参数。在运行命令后通过clearing out the parameters解决此问题(或者更好:为第二个查询创建一个新的SqlCommand)。
{{1}}