Question

My work here is working but if search 1 it display 40 instead of 900 here is my work:

command.CommandType = CommandType.Text;
command.CommandText = ("SELECT * FROM Computation WHERE Transaction_ID LIKE '" + textBox1.Text.ToString() + "%'");

command.Connection = connection;    
connection.Open();  
var reader = command.ExecuteReader();              
while (reader.Read())
{                  
   textBox2.Text = (String.Format("{0000,0:N2}", Int32.Parse(reader["Total_Bill"].ToString())));
}                  
connection.Close();

enter image description here

Was it helpful?

Solution

As I wrote in my comment, I don't understand why you used LIKE here but you can ExecuteScalar which is perfect in your situation.

Executes the query, and returns the first column of the first row in the result set returned by the query.

Like;

command.CommandType = CommandType.Text;
command.CommandText = ("SELECT Total_Bill FROM Computation WHERE Transaction_ID = @ID");
command.Parameters.AddWithValue("@ID", textBox1.Text);    
command.Connection = connection;
try
{    
  connection.Open();  
  textBox2.Text = (String.Format("{0000,0:N2}", command.ExecuteScalar()));            
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}                 
connection.Close();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top