Error in asp.net linked to sqlserver

0

I have this code:

<head runat="server">

                  

    <div class="barraCima">
         <img class="simbolo" alt="icon" src="images/doctor.png"/>
    </div>

    <div class="main">
     <div class="menu">
         <div class = "glicemia">
             <a class = "glicemia" href="Glicemia.aspx"><h3>Medição Glicemia</h3></a>
         </div>

         <div class = "pressao">                  
              <a class = "pressao" href="PressaoArterial.aspx"><h3> Medição Pressão Arterial</h3></a>
         </div>
     </div>
     <div class="medicao">
         <div class ="tituloMedicao">
              <img class="icong" alt="icon" src="images/blood-pressure-ico.png"/><h1>Glicemia</h1>
         </div>
     <div class = "valoresglicemia">
         <div class="values">
         <div class ="valores">
             <div class="nome">
                 <img class="iconglic" alt="icon" src="images/patient11.png"/><p>Nome</p>
             </div>
             <div class="textNome">               
                 <asp:label id="nome" runat="server"></asp:label>
             </div>
             <div class="medico">
                 <img class="iconglic" alt="icon" src="images/medicos.png"/><p>Médico</p>
             </div>
             <div class="textMedico">
                  <asp:label id="medico" runat="server"></asp:label>
             </div>
             <div class="data">
                 <img class="iconglic" alt="icon" src="images/data.png"/><p>Data</p>
             </div>
             <div class="textData">
                  <asp:TextBox class="bData" type="date" id="data" runat="server" />
             </div>
             <div class="valor">
                 <img class="iconglic" alt="icon" src="images/39.png"/><p>Valor</p>
              </div>
             <div class =" textValor">
                  <asp:TextBox class="bData" type="text" id="valor" runat="server" />
             </div>
         </div>
         </div>
      </div>
     </div>
     </div>

        <div class="footer">
            <div class ="guardar">
                <asp:Button class="buttsave" runat="server" OnClick="ButtonSave_Click" Text="Guardar"> </asp:Button>
            </div>
            <div class =" voltar">
                <a href="InformacoesPessoais.aspx"> <img class="save" alt="icon" src="images/left-arrow.png"/></a>
            </div>
            <div class =" desligar">
              <button class="buttsave"> <img class="save" alt="icon" src="images/shut-down-icon.png"/></button>
            </div>
        </div>

   </div>
</form>

But when I execute and click on save it gives me this error:

  

An error has occurred in System.Data.SqlClient.SqlException (0x80131904): Invalid object name 'RegistoMedicao'. in System.Data.SqlClient.SqlConnection.OnError (SqlException exception, Boolean breakConnection, Action 1 wrapCloseInAction) em System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action 1 wrapCloseInAction) in System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning (TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) in System.Data.SqlClient .TdsParser.TryRun (runBehavior RunBehavior, cmdHandler SqlCommand, SqlDataReader datastream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean & dataReady) in System.Data.SqlClient.SqlCommand.FinishExecuteReader (SqlDataReader ds runBehavior RunBehavior, String resetOptionsString, IsInternal Boolean, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted) in System.Data.SqlClient.SqlCommand.RunExecuteReaderTds (CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task & Task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) in System.Da ta.SqlClient.SqlCommand.RunExecuteReader (CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource 1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) em System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource 1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean & usedCache, Boolean asyncWrite, Boolean inRetry) in System.Data.SqlClient.SqlCommand.ExecuteNonQuery () in UserList.ButtonSave_Click (Object sender, EventArgs, and) in C: \ Users \ Vera \ Desktop \ Final ES \ EngineeringSoftware \ EngineeringSoftware \ Glycemic .aspx.cs: line 57 ClientConnectionId: a5bde982-612c-4eb6-89f6-ef68576897e5 Error Number: 208, State: 1, Class: 16

I do not even understand where the error is, here is the remaining code to call the database:

 using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;




  public partial class RegistosUtente : System.Web.UI.Page
    {
        public SqlConnection conn = new SqlConnection(@"data source=DESKTOP-5B34D6V\SQLEXPRESS;initial catalog=EngenhariaSoft;persist security info=True;user id=sa;MultipleActiveResultSets=True;");
    protected void Page_Load(object sender, EventArgs e)
    {

}
protected void ButtonSave_Click(object sender, EventArgs e)
{

    String connectionString = @"data source=DESKTOP-5B34D6V\SQLEXPRESS;initial catalog=EngenhariaSoft;persist security info=True;user id=sa;password=123456;MultipleActiveResultSets=True;";
    string _query = "INSERT INTO RegistoMedicao (DataRegisto,ValorMedido) values (@DataRegisto,@ValorMedido)";
    using (SqlConnection conn = new SqlConnection(connectionString))
    {
        using (SqlCommand comm = new SqlCommand())
        {
            comm.Connection = conn;
            comm.CommandType = CommandType.Text;
            comm.CommandText = _query;
            //comm.Parameters.AddWithValue("@DataRegisto", DateTime.ParseExact(data.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture));
            comm.Parameters.AddWithValue("@DataRegisto", DateTime.Now.ToString("dd-MM-yyyy"));// se nao der testa desta maneira
            comm.Parameters.AddWithValue("@ValorMedido", valor.Text);
            try
            {
                conn.Open();
                comm.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Response.Write("Ocorreu um erro" + ex.ToString());
            }
        }
    }
}

}

    
asked by anonymous 11.06.2018 / 21:17

0 answers