문제

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

도움이 되었습니까?

해결책

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();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top