前台:
<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=********;Password=*********;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();
}