I have a problem with my program: "System.Data.SqlClient.SqlException (0x80131904): The request for procedure 'Bi_medicao' failed because 'Bi_medicao' is a table object." And I can't figure out what it might be ...
while (true)
{
var dataRx = myPort.ReadLine();
var underscore = dataRx.Split('_');
humidade = underscore[0];
temperatura = underscore[1];
heatIndex = underscore[2];
lpgGas = underscore[3];
monoCarbo = underscore[4];
smoke = underscore[5];
Console.WriteLine(humidade);
Console.WriteLine(temperatura);
Console.WriteLine(heatIndex);
Console.WriteLine(lpgGas);
Console.WriteLine(monoCarbo);
Console.WriteLine(smoke);
Console.WriteLine(DateTime.Now);
Console.WriteLine("___________________");
SqlConnection ss = new SqlConnection("Data Source=(LocalDb)\\MSSQLLocalDB;Initial Catalog=tupaidb;Integrated Security=True");
ss.Open();
if (ss.State == System.Data.ConnectionState.Open)
{
SqlDataAdapter aa = new SqlDataAdapter("dbo.Bi_medicao", ss);
aa.SelectCommand.CommandType = CommandType.StoredProcedure;
aa.SelectCommand.Parameters.Add("@med_hum", SqlDbType.VarChar, (50)).Value = humidade;
aa.SelectCommand.Parameters.Add("@med_temp", SqlDbType.VarChar, (50)).Value = temperatura;
aa.SelectCommand.Parameters.Add("@med_lpg", SqlDbType.VarChar, (50)).Value = lpgGas;
aa.SelectCommand.Parameters.Add("@med_co", SqlDbType.VarChar, (50)).Value = monoCarbo;
aa.SelectCommand.Parameters.Add("@med_fumo", SqlDbType.VarChar, (50)).Value = smoke;
aa.SelectCommand.Parameters.Add("@med_data", SqlDbType.DateTime).Value = DateTime.Now;
aa.SelectCommand.ExecuteNonQuery();
ss.Close();
}
}
I managed to solve it I will leave here the code that I changed to help future people!
SqlConnection connString = new SqlConnection("Data Source=(LocalDb)\\MSSQLLocalDB;Initial Catalog=tupaidb;Integrated Security=True");
connString.Open();
if (connString.State == System.Data.ConnectionState.Open)
{
SqlDataAdapter aa = new SqlDataAdapter("[dbo].[dbo.Bi_medicaoInset]", connString);
aa.SelectCommand.CommandType = CommandType.StoredProcedure;
aa.SelectCommand.Parameters.Add("@med_hum", SqlDbType.VarChar, (50)).Value = humidade;
aa.SelectCommand.Parameters.Add("@med_temp", SqlDbType.VarChar, (50)).Value = temperatura;
aa.SelectCommand.Parameters.Add("@med_lpg", SqlDbType.VarChar, (50)).Value = lpgGas;
aa.SelectCommand.Parameters.Add("@med_co", SqlDbType.VarChar, (50)).Value = monoCarbo;
aa.SelectCommand.Parameters.Add("@med_fumo", SqlDbType.VarChar, (50)).Value = smoke;
aa.SelectCommand.Parameters.Add("@med_data", SqlDbType.DateTime).Value = DateTime.Now;
aa.SelectCommand.ExecuteNonQuery();
connString.Close();
}
User contributions licensed under CC BY-SA 3.0