C
C#2y ago
yumo

❔ sql statment Count *

Why is this not displaying on my textbox txtEnsaio the max number of Ensaios that are in the table tbl_ensaios with the id that's on the txtIdFerramenta?
private void funcGetEnsaioNumber()
{
string str = "SELECT COUNT(*) FROM tbl_ensaios WHERE idProjetos = @idProjetos";
SqlCommand cmd = new SqlCommand(str, con);
cmd.Parameters.AddWithValue("@idProjetos", txtIdFerramenta.Text);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
txtEnsaioID.Text = dr[0].ToString();
}
con.Close();
}
private void funcGetEnsaioNumber()
{
string str = "SELECT COUNT(*) FROM tbl_ensaios WHERE idProjetos = @idProjetos";
SqlCommand cmd = new SqlCommand(str, con);
cmd.Parameters.AddWithValue("@idProjetos", txtIdFerramenta.Text);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
txtEnsaioID.Text = dr[0].ToString();
}
con.Close();
}
i want to get the id from the txtIdFerramenta and get the max number of rows with that same id on the tbl_ensaios. This is just giving me 0. I run this sql statment on a query on the database and gets me the result
2 Replies
NDOT
NDOT2y ago
bro do the following take that txtIdFerramenta.Text into a variable, and then pass it as argument to the method that do the query like int idFerramenta = txtIdFerramenta.Text
private void funcGetEnsaioNumber(int id)
{
cmd.Parameters.AddWithValue("@idProjetos", id);
}
private void funcGetEnsaioNumber(int id)
{
cmd.Parameters.AddWithValue("@idProjetos", id);
}
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server