Asp.net error connected to sqlserver

Asked

Viewed 103 times

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 run and click save it gives me this error:

Errorsystem.Data.Sqlclient.Sqlexception (0x80131904): Invalid Object name 'Registomedicao'. em 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) em System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) em System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) em System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted) em 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) em System.Data.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) em System.Data.SqlClient.SqlCommand.ExecuteNonQuery() em RegistosUtente.ButtonSave_Click(Object sender, EventArgs e) in C: Users Vera Silva Desktop Final ES Engineeringsoftware Engineeringsoftware Glicemia.aspx.Cs:line 57 Clientconnectionid:a5bde982-612c-4eb6-89f6-ef68576897e5 Error Number:208,State:1,Class:16

I don’t really understand where the bug is, here’s the rest of the code calling from 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());
            }
        }
    }
}

}

  • is RegistoMedicao or RegistroMedicao?

  • @Marconi Registomedicao

  • Another thing, when I put my local connection string I don’t put the passoword and no access user. Are you sure your connection string is correct?

  • But I have password and username to login to sql server so that’s why I put it, but I don’t know if it’s right no.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.