更新时如何把空值NULL更新回数据库?
WorldNewsAdd.cs源码:
public static bool updateWorldNews(WorldNewsType t)
{
try
{
SqlConnection con = DB.createCon();
con.Open();
SqlCommand cmd = new SqlCommand( "update WorldNews set WorldNewsDate= ' " + t.WorldNewsDate + " ' where WorldNewsID= ' " + t.WorldNewsID + " ' ", con);
cmd.ExecuteNonQuery();
return true;
}
catch (Exception e)
{
return false;
}
}
更新页update.aspx.cs后台代码:
protected void btnUpdate_Click(object sender, EventArgs e)
{
string strID = Request.QueryString[ "WorldNewsID "];
WorldNewsType t = new WorldNewsType();
t.WorldNewsID = strID;
if (this.txtWorldNewsDate.Text == null || this.txtWorldNewsDate.Text == " ")
{
t.WorldNewsDate = DBNull.Value.ToString();
}
else
{
t.WorldNewsDate = this.txtWorldNewsDate.Text;
}
if (WorldNewsAdd.updateWorldNews(t))
{
Response.Write( "成功 ");
}
else
{
Response.Write( "失败 ");
&nb