📄 mysqlnull.aspx.cs
字号:
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.Data.SqlClient;
using System.Configuration;
namespace Example_7_10
{
/// <summary>
/// Summary description for MySQLNULL.
/// </summary>
public class MySQLNULL : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label TureNULL;
protected System.Web.UI.WebControls.Label FalseNULL;
protected System.Web.UI.WebControls.Label NULLTrue;
protected System.Web.UI.WebControls.Label NullFalse;
protected System.Web.UI.WebControls.Label NULLNULL;
protected System.Web.UI.WebControls.Button GetNULLValue;
private readonly string SQLCONNECTIONSTRING = ConfigurationSettings.AppSettings["SQLCONNECTIONSTRING"].ToString();
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
///初始化布尔运算的表达式
SetNULL();
}
}
private void SetNULL()
{
TureNULL.Text = "True AND NULL";
FalseNULL.Text = "False AND NULL";
NullFalse.Text = "NULL AND False";
NULLTrue.Text = "NULL AND True";
NULLNULL.Text = "NULL AND NULL";
}
private void CalNULLValue()
{
TureNULL.Text = GetNULLValues(TureNULL.Text);
FalseNULL.Text = GetNULLValues(FalseNULL.Text);
NullFalse.Text = GetNULLValues(NullFalse.Text);
NULLTrue.Text = GetNULLValues(NULLTrue.Text);
NULLNULL.Text = GetNULLValues(NULLNULL.Text);
}
private string GetNULLValues(string nullString)
{
String nullValue = "";
switch(nullString)
{
case "True AND NULL":
{
nullString = "(1=1) AND (1=NULL)";
break;
}
case "False AND NULL":
{
nullString = "(1=0) AND (1=NULL)";
break;
}
case "NULL AND False":
{
nullString = "(1=NULL) AND (1=0)";
break;
}
case "NULL AND True":
{
nullString = "(1=NULL) AND (1=1)";
break;
}
case "NULL AND NULL":
{
nullString = "(1=NULL) AND (1=NULL)";
break;
}
default:break;
}
///从数据库中Tabs表获取所有记录
String cmdText = "SELECT NULLValue = (CASE WHEN " + nullString + " THEN 'True' ELSE 'FALSE' END)";
SqlConnection myConnection = new SqlConnection(SQLCONNECTIONSTRING);
SqlCommand myCommand = new SqlCommand(cmdText,myConnection);
///执行数据库查询
myConnection.Open();
SqlDataReader dr = myCommand.ExecuteReader();
if(dr.Read())
{
nullValue = dr["NULLValue"].ToString();
}
///关闭读取器和数据库的链接
dr.Close();
myConnection.Close();
return(nullValue);
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.GetNULLValue.Click += new System.EventHandler(this.GetNULLValue_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void GetNULLValue_Click(object sender, System.EventArgs e)
{
CalNULLValue();
GetNULLValue.Enabled = false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -