I have this table which contains a few's questions:
<table>
<tr><td><b>Utilizador:</b></td><td><asp:Label ID="username" runat="server"></asp:Label></td></tr>
<tr><td><b>Telefone da Empresa:</b></td><td><asp:TextBox ID="empresa" runat="server" MaxLength="13"></asp:TextBox> (Exemplo: +351234925xxx)</td></tr>
<tr><td><b>2º Telefone:</b></td><td><asp:TextBox ID="empresa2" runat="server" MaxLength="4"></asp:TextBox> (Exemplo: xxxx)</td></tr>
<tr><td><b>Telemóvel:</b></td><td><asp:TextBox ID="telemovel" runat="server" MaxLength="13"></asp:TextBox> (Exemplo: +3519xxxxxxxx)</td></tr>
<tr><td colspan="2"><asp:Label ID="lblInfo" runat="server" Font-Bold="True"></asp:Label></td></tr>
<tr><td><asp:Button ID="cmdSave" runat="server" Text="Guardar" onclick="cmdSave_Click" /></td><td></td></tr>
</table>
my goal is
when page loads verify if the username.Text = "[" + HttpContext.Current.User.Identity.Name + "]";
i pretent do verify if already exist in access database if YES show the table with the information to update
if NO show the table to insert the information
how can I do such thing working?
my code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
using System.Security.Principal;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
username.Text = "[" + HttpContext.Current.User.Identity.Name + "]";
}
protected void cmdSave_Click(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,@username)";
using (Conn)
{
Conn.Open();
OleDbCommand myCommand = new OleDbCommand(insertCmd, Conn);
myCommand.Parameters.AddWithValue("@Empresa", empresa.Text);
myCommand.Parameters.AddWithValue("@Empresa2", empresa2.Text);
myCommand.Parameters.AddWithValue("@Telemovel", telemovel.Text);
myCommand.Parameters.AddWithValue("@username", HttpContext.Current.User.Identity.Name);
Response.Write(" ");
myCommand.ExecuteNonQuery();
lblInfo.Text = "Dados guardados!";
lblInfo.ForeColor = System.Drawing.Color.Green;
}
}
}