前台:
<form id="form1" runat="server" action="./Demo2.aspx">
<div>
<table style="height: 326px; width: 935px">
<tr>
<td class="auto-style3">キーワード検索:
<asp:TextBox ID="SelectText" runat="server" Width="428px" Height="16px" Text="社員氏名をローマ字または漢字で検索してください"></asp:TextBox>
<asp:Button ID="SelectBtn" runat="server" Text="検索" Width="103px" OnClick="SelectBtn_Click" />
后台:
protected void SelectBtn_Click(object sender, EventArgs e)
{
string sqlCon = "Data Source=tcp:m7pevx6s1h.database.windows.net;Initial Catalog=srpnotesdev02;User ID=o365wp@m7pevx6s1h;Password=P@ssw0rd!;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;";
SqlConnection scon = new SqlConnection(sqlCon);
if (scon.State != ConnectionState.Open)
{
scon.Open();
}
string sql;
string text = this.SelectText.Text.ToString();
string parm = @"[/^[a-zA-Z]+$/]";
Regex rg = new Regex(parm);
Match mh = rg.Match(text);
if (mh.Success)
{
sql = " select EName,UniqueNo,jno,name,GroupSName_1,GroupSName_2,GroupSName_3,O365_Email from MainForm where EName='" + this.SelectText.Text.ToString() + "' ";
}
else
{
sql = " select EName,UniqueNo,jno,name,GroupSName_1,GroupSName_2,GroupSName_3,O365_Email from MainForm where name='" + this.SelectText.Text.ToString() + "' ";
}
SqlCommand scmd = new SqlCommand(sql, scon);
SqlDataAdapter sda = new SqlDataAdapter(scmd);
DataTable dt = new DataTable();
sda.Fill(dt);
Console.WriteLine(dt);
Rept.DataSource = dt;
Rept.DataBind();
}
}
}