我就是这样判断的啊!但是对于数据库字段我用的是DBNull.Value

解决方案 »

  1.   

    string s;
    if(s!=null && !s.Equals(""))
    {do something}
    else
    {do something}我觉得这个最保险!!!
      

  2.   

    測試過沒問題.
    如果你開始把ojbect1="";就不行了注意""!=null
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Configuration;
    using System.Data.SqlClient;
    namespace Debug
    {
    /// <summary>
    /// WebForm1 的摘要描述。
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
    protected System.Data.SqlClient.SqlConnection sqlConn;
    protected System.Web.UI.WebControls.Button Button1;
    protected System.Data.SqlClient.SqlCommand sqlComm;
    protected string s;


    private void Page_Load(object sender, System.EventArgs e)
    {
    //sqlConnection1.ConnectionString=ConfigurationSettings.AppSettings["YINSConn"];
    } #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 此呼叫為 ASP.NET Web Form 設計工具的必要項。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 此為設計工具支援所必需的方法 - 請勿使用程式碼編輯器修改
    /// 這個方法的內容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.sqlConn = new System.Data.SqlClient.SqlConnection();
    this.sqlComm = new System.Data.SqlClient.SqlCommand();
    // 
    // sqlComm
    // 
    this.sqlComm.Connection = this.sqlConn;
    this.Button1.Click += new System.EventHandler(this.Button1_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void Button1_Click(object sender, System.EventArgs e)
    {

    if (s==null)
    {
    Response.Write("OK");
    Response.End();
    }
    }
    }
    }
      

  3.   

    你用String变量肯定可以用null判断,试试判断DateTime类.
      

  4.   

    vb中就好办了,用 is nothing就可以判断了,但是C#中我还没找到简单的办法,只能用Convert.IsDbNull()
      

  5.   

    当然可以
    o==null
    如果返回true,那么o就是空
      

  6.   

    xcode21(X-Code)请自己动动手试试判断DateTime类,不要想当然的轻易作判断.
      

  7.   

    既然为空,调用 Equals() 不就要出现 NullReferenceException  ?