我将此表格用于回答的用户名:
<table>
<tr><td><b>User:</b></td><td><asp:Label ID="useren" runat="server"></asp:Label></td></tr>
<tr><td><b>Business:</b></td><td><asp:TextBox ID="business" runat="server" MaxLength="13"></asp:TextBox> (Example: +351234925xxx)</td></tr>
<tr><td><b>Business 2:</b></td><td><asp:TextBox ID="business2" runat="server" MaxLength="4"></asp:TextBox> (Example: xxxx)</td></tr>
<tr><td><b>Mobile:</b></td><td><asp:TextBox ID="mobile" runat="server" MaxLength="13"></asp:TextBox> (Example: +3519xxxxxxxx)</td></tr>
<tr><td colspan="2"><asp:Label ID="Label1" runat="server" Font-Bold="True"></asp:Label></td></tr>
<tr><td><asp:Button ID="Button1" runat="server" Text="Save" onclick="cmdSave_Click2" /></td><td></td></tr>
</table>
要从windows login-user获取用户名,我在后面的代码中有这个:
protected void Page_Load(object sender, EventArgs e)
{
useren.Text = "[" + HttpContext.Current.User.Identity.Name + "]";
}
并将所有text.box从表保存到ACCESS DataBase我有:
protected void cmdSave_Click2(object sender, EventArgs e)
{
string sFilePath = Server.MapPath("Database3.accdb");
OleDbConnection Conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + sFilePath + ";Persist Security Info=False;");
string insertCmd = "INSERT INTO colaborador(Empresa,Empresa2,Telemovel,username) VALUES (@Empresa,@Empresa2,@Telemovel,@useren)";
using (Conn)
{
Conn.Open();
OleDbCommand myCommand = new OleDbCommand(insertCmd, Conn);
myCommand.Parameters.AddWithValue("@Empresa", business.Text);
myCommand.Parameters.AddWithValue("@Empresa2", business2.Text);
myCommand.Parameters.AddWithValue("@Telemovel", mobile.Text);
myCommand.Parameters.AddWithValue("@useren", HttpContext.Current.User.Identity.Name);
myCommand.ExecuteNonQuery();
Label1.Text = "Saved Successfull!";
Label1.ForeColor = System.Drawing.Color.Green;
}
}
但是如何检测如果用户已经已经回答,并说出“用户已经回答”或者例如。显示该用户的数据库存储数据, Else 显示创建的表格以显示text.box。