Click here to Skip to main content
15,889,651 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
textbox1 value come from data base and textbox2 value from data base and subtract textbox1-textbox2 and vale print on textbox3 how it check all id from data base where i get value greater than 1 it execute and show that id data from data base

What I have tried:

i try looping their but i cant define it
Posted
Comments
Suvendu Shekhar Giri 16-Feb-16 3:21am    
Share the relevant code (not all) you have tried so far.
Member 12330102 16-Feb-16 3:38am    
private void display()
{
try

{

string ss2 = "Select Date_of_maintenance,Next_date_of_maintenance From CMC ";
if (con.State != ConnectionState.Open)
con.Open();
SqlCommand command = new SqlCommand(ss2, con);
command.ExecuteNonQuery();

DataSet dataSet = new DataSet();
SqlDataReader reader = command.ExecuteReader();
reader.Read();

if (reader.HasRows)
{
textBox1.Text = reader[0].ToString();
textBox2.Text = reader[1].ToString();


DateTime date1 = Convert.ToDateTime(textBox1.Text);

DateTime date2 = Convert.ToDateTime(textBox2.Text);

TimeSpan ts = date2 - date1;

textBox3.Text = ts.TotalDays.ToString();
con.Close();
con.Open();





int value;
if (Int32.TryParse(textBox3.Text, out value))
{
if (value > 0)
{



string ss21 = "Select Machine_Id,Machine_name,S_provider_name,Contact_number From CMC ";
if (con.State != ConnectionState.Open)
con.Open();
SqlCommand command1 = new SqlCommand(ss21, con);
command1.ExecuteNonQuery();

DataSet dataSet1 = new DataSet();
SqlDataReader reader1 = command1.ExecuteReader();
reader1.Read();

if (reader1.HasRows)
{


label23.Text = reader1[0].ToString();
label24.Text = reader1[1].ToString();
label25.Text = reader1[2].ToString();
label26.Text = reader1[3].ToString();
}
}
else
{
// not a number in textbox
}


}
Member 12330102 16-Feb-16 3:39am    
it show or display for only one id. it not check whole database id

1 solution

If both the values for Textbox1 and Textbox2 are coming from the database and you just need to show the substraction of these two values in Textbox3 then you can build the query something like following
SQL
SELECT Value1, Value2, (Value1-Value2) AS Value3
FROM YourTable

and if you need to apply any filter as you have mentioned in the question, you can do something like-
SQL
SELECT Value1, Value2, CASE WHEN (Value1-Value2)>1 THEN (Value1-Value2) ELSE NULL END AS Value3
FROM YourTable


If your requirement is something else then this, please let me know with some words of description about your requirement.

:)
 
Share this answer
 
Comments
Member 12330102 16-Feb-16 4:03am    
if in data base first id value is smaller than 1 ,it go and check another id it repited till it not get text box3 > 1

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900