Hello, i need help in some subject i can't handle with for few days. lets say i have form that handle with some rent order (like....billiboards) after the user choose the number of the billboard and the Location and everything else, he need to choose 2 dates. one for the publish day and one for the getOFF day. i have odbc database that hold all the information about the billboards etc... how can i make some "if" or queries that will check that this billboard is not ordered in that range of days? for now i only have the insert handle. PLEASE HELP.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Odbc;

namespace forumArt
{
    public partial class addNewCampaign : Form
    {
        public addNewCampaign()
        {
            InitializeComponent();
        }

        private void addNewCampaign_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dataSet1.customers' table. You can move, or remove it, as needed.
            this.customersTableAdapter.Fill(this.dataSet1.customers);
            // TODO: This line of code loads data into the 'dataSet1.signsDetails' table. You can move, or remove it, as needed.
            this.signsDetailsTableAdapter.Fill(this.dataSet1.signsDetails);

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (signNumber.Text == "")
            {
                MessageBox.Show("חובה לבחור את מספר השלט");
            }
            if (companyName.Text == "")
            {
                MessageBox.Show("נא לבחור את שם החברה המזמינה");
            }
            else
            {
                try
                {
                    OdbcConnection conn = new OdbcConnection("dsn=forumArtDataBase");
                    OdbcCommand cmd = new OdbcCommand("insert into orders(signNumber,fromDate,toDate,companyName,comments) values ('" + signNumber.Text + "','" + fromDate.Text + "','" + toDate.Text + "','" + companyName.Text + "','" + comments.Text + "')", conn);
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    conn.Close();
                    MessageBox.Show("ההזמנה התווספה בהצלחה");
                    Close();
                }
                catch (OdbcException ex)
                {

                    MessageBox.Show("התבצעה שגיאה בעת ניסיון ההתחברות למסד הנתונים" + ex);
                }
            }
        }
    }
}

Hello, i need help in some subject i can't handle with for few days. lets say i have form that handle with some rent order (like....billiboards) after the user choose the number of the billboard and the Location and everything else, he need to choose 2 dates. one for the publish day and one for the getOFF day. i have odbc database that hold all the information about the billboards etc... how can i make some "if" or queries that will check that this billboard is not ordered in that range of days? for now i only have the insert handle. PLEASE HELP.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Odbc;

namespace forumArt
{
    public partial class addNewCampaign : Form
    {
        public addNewCampaign()
        {
            InitializeComponent();
        }

        private void addNewCampaign_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dataSet1.customers' table. You can move, or remove it, as needed.
            this.customersTableAdapter.Fill(this.dataSet1.customers);
            // TODO: This line of code loads data into the 'dataSet1.signsDetails' table. You can move, or remove it, as needed.
            this.signsDetailsTableAdapter.Fill(this.dataSet1.signsDetails);

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (signNumber.Text == "")
            {
                MessageBox.Show("חובה לבחור את מספר השלט");
            }
            if (companyName.Text == "")
            {
                MessageBox.Show("נא לבחור את שם החברה המזמינה");
            }
            else
            {
                try
                {
                    OdbcConnection conn = new OdbcConnection("dsn=forumArtDataBase");
                    OdbcCommand cmd = new OdbcCommand("insert into orders(signNumber,fromDate,toDate,companyName,comments) values ('" + signNumber.Text + "','" + fromDate.Text + "','" + toDate.Text + "','" + companyName.Text + "','" + comments.Text + "')", conn);
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    conn.Close();
                    MessageBox.Show("ההזמנה התווספה בהצלחה");
                    Close();
                }
                catch (OdbcException ex)
                {

                    MessageBox.Show("התבצעה שגיאה בעת ניסיון ההתחברות למסד הנתונים" + ex);
                }
            }
        }
    }
}

end quote.

Hi Check the code below, how that helps...

SELECT 
  booking.bookingid,
  booking.startdate,
  property.address,
  booking.propertyid,
  booking.userid,
  booking.package
FROM
  booking
  INNER JOIN property ON (booking.userid = property.userid) AND (booking.propertyid = property.propertyid)
WHERE
  (booking.startdate > 20 / 07 / 2009) AND 
  (booking.startdate < 27 / 07 / 2009)
ORDER BY
  booking.startdate DESC

i can't handle this code i can't understand it. can you be more specify? the form fields are: signNumber (send number in string), from date (send date), toDate (send date), companyName (send string), and comments (string). there is number for each billboard so the code need to check th DB if this number of sign is availble between this range of dates. One think i can say for sure, this is the fifth forum iv'e asked and no one give a solution..........:-(

how about this code:

SELECT * FROM BillBoardTable WHERE (fromDate > 20 / 07 / 2009) AND
(endDate < 27 / 07 / 2009)

$q="SELECT * FROM BillBoardTable WHERE (fromDate > 20 / 07 / 2009) AND
(endDate < 27 / 07 / 2009)";

$result = mysql_query($q, $conn); 

 $data = mysql_fetch_array($result)
 if($data.length>0)
 {
     echo('ALready booked. Choose different dates');
 }
select count(*) orders where (signNumber='required_sign_number' )and ( ( (fromDate > required_toDate ) or (toDate < required_fromDate )  )

Assuming your required_fromDate < required_toDate which you have to check if you not have already.

NOTHING working. Ablitz your code in PHP and i work with C#. iv'e try servel options but still NOT. the code have to check the "signNumber" too not only the range between dates. in ABSTRACT = "take the signNumber and check if is available between that two dates if yes, insert to the database if not throw messagebox - NOT AVAILABLE"

PLEASE.....ANYONE, its a college project to present by sunday....:-(

NOTHING working. Ablitz your code in PHP and i work with C#. iv'e try servel options but still NOT. the code have to check the "signNumber" too not only the range between dates. in ABSTRACT = "take the signNumber and check if is available between that two dates if yes, insert to the database if not throw messagebox - NOT AVAILABLE"

LightHead provided you with a query where you check for signNumber too.

This is what you do:
1. Create Connection to Database (you should know how to do that, if not, look for tutorials there are plenty of those around)
2. Query Database (use LightHead's SQL query)
3. Handle Response

Make sure that startDate endDate ARE DATES in your database and not just simple TEXT or VARCHAR...

elidotnet,
1. Can I see the table structure? i.e - columnname and datatype.
2. How many tables are used?

elidotnet,
1. Can I see the table structure? i.e - columnname and datatype.
2. How many tables are used?

Hi, thanks for replay, the table call "orders" and the coulmns are: orderID (PK int), signNumber (that get sting value from combobox), fromDate (get Date from datePicker), toDate (get Date from datePicker), companyName (string) and comments (string). whene the user fillup the form and click to send the signNumber and the fromDate and toDate are the important values. the code need to look if there is a record in the orders table that hold the same signNumber and if this signNumber available between the fromDate and toDate. in the Database there are more 3 tables "agents", "billboards" and "customers" non of them have directlly use for this prucedur. Please, this is the last event to finish this project for college.

The code need to look if there is a record in the orders table that hold the same signNumber and if this signNumber available between the fromDate and toDate.

OdbcConnection conn = new OdbcConnection("dsn=forumArtDataBase");
OdbcCommand cmd;

string sql="select signNumber from orders where signNumber='" + signNumber.Text +"' and fromDate='" +  fromDate.Text + "' and toDate='" + toDate.Text + "'";

cmd=new OdbcCommand(sql,conn);
cbject cret;

conn.Open();
cret=cmd.ExecuteScalar();
if(cret==null)
  {
    // No match
   } 
else
 {
    // Match
  }

 cmd = new OdbcCommand("insert into orders(signNumber,fromDate,toDate,companyName,comments) values ('" + signNumber.Text + "','" + fromDate.Text + "','" + toDate.Text + "','" + companyName.Text + "','" + comments.Text + "')", conn);

cmd.ExecuteNonQuery();
conn.Close();

MessageBox.Show("ההזמנה התווספה בהצלחה");

cbject did you mean object?

its still not working. i guess it because the if(cret==null) thing no?

It's object or Object.

object cret;

conn.Open();
cret=cmd.ExecuteScalar();
if(cret==null)
  {
    // No match
   } 
else
 {
    // Match
  }

its give error [22018]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.