I was published this problem over 10 forums and no one know what the solution for that. i try to make some application that deal with billboards and advertising. When i want to make order for some billboard i need to fillup the billboard number (wich his number is string and not integer) and i need to choose between 2 dates when the billboard is up (for example 01.08.2009 dd;mm;yyyy) for 14 days (until 14.08.2009). This is the first section! If i want to make new order and i choose the same billboard number and the same dates the application need NOT to let me doing the order by messageBox "The billboard is not availble". i was wrote some code and the problem is: i was ordered sign number 23 (for example) between the dates 1.8.2009 - 14.8.2009, then i was try to order the same sign number between 28.7.2009 - 12.8.2009, the application DONT ACCEPT THE ORDER cause the dates was blocked. but then i make order with the same sign number between 5.8.2009 - 13.8.2209 then the application Accept the order.....????????? the code is:

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.agents' table. You can move, or remove it, as needed.

 

this.agentsTableAdapter.Fill(this.dataSet1.agents); 

 


// 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"); 

 


var cmdCheck = new OdbcCommand("SELECT Count(*) FROM Orders WHERE signNumber = ? AND (fromDate BETWEEN ? and ? OR toDate BETWEEN ? AND ?)", conn); 

cmdCheck.Parameters.Add(


new OdbcParameter("@p1", OdbcType.Int)).Value = signNumber.Text; 

cmdCheck.Parameters.Add(


new OdbcParameter("@p2", OdbcType.DateTime)).Value = fromDate.Value; 

cmdCheck.Parameters.Add(


new OdbcParameter("@p3", OdbcType.DateTime)).Value = toDate.Value; 

cmdCheck.Parameters.Add(


new OdbcParameter("@p4", OdbcType.DateTime)).Value = fromDate.Value; 

cmdCheck.Parameters.Add(


new OdbcParameter("@p5", OdbcType.DateTime)).Value = toDate.Value; 

conn.Open();

 


int result = Convert.ToInt32(cmdCheck.ExecuteScalar()); 

conn.Close();

 


if (result > 0) 

{

 


MessageBox.Show(" "); 

 


return; 

}

 


else

{

 

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

conn.Open();

indata.ExecuteNonQuery();

conn.Close();

 


MessageBox.Show(" "); 

Close();

}

 

}

 


catch (OdbcException ex) 

{

 


MessageBox.Show(" " + ex); 

}

}

}

}

}

I can't even read your post with all the extra line breaks and no code tags. Try posting it again:

[code=c#] ...code here

[/code]

sorry, here is the code again

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.agents' table. You can move, or remove it, as needed.
            this.agentsTableAdapter.Fill(this.dataSet1.agents);
            // 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");
                    var cmdCheck = new OdbcCommand("SELECT Count(*) FROM Orders WHERE signNumber = ? AND (fromDate BETWEEN ? and ? and toDate BETWEEN ? AND ?)", conn);
                    cmdCheck.Parameters.Add(new OdbcParameter("@p1", OdbcType.VarChar)).Value = signNumber.Text;
                    cmdCheck.Parameters.Add(new OdbcParameter("@p2", OdbcType.DateTime)).Value = fromDate.Value;
                    cmdCheck.Parameters.Add(new OdbcParameter("@p3", OdbcType.DateTime)).Value = toDate.Value;
                    cmdCheck.Parameters.Add(new OdbcParameter("@p4", OdbcType.DateTime)).Value = fromDate.Value;
                    cmdCheck.Parameters.Add(new OdbcParameter("@p5", OdbcType.DateTime)).Value = toDate.Value;
                    conn.Open();
                    int result = Convert.ToInt32(cmdCheck.ExecuteScalar());
                    conn.Close();
                    if (result > 0)
                    {
                        MessageBox.Show("השלט אינו פנוי בתאריך המבוקש");
                        return;
                    }
                    else
                    {
                        OdbcCommand indata = new OdbcCommand("insert into orders (signNumber,fromDate,toDate,companyName,comments) values ('"+signNumber.Text+"','"+fromDate.Text+"','"+toDate.Text+"','"+companyName.Text+"','"+comments.Text+"')", conn);
                        conn.Open();
                        indata.ExecuteNonQuery();
                        conn.Close();
                        MessageBox.Show("ההזמנה נקלטה בהצלחה");
                        Close();
                    }

                                    
                }
                catch (OdbcException ex)
                {

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

Do not add your tags inside of a [quote ] or [noparse ]. Try one more time. After you have entered your code click "GO ADVANCED" and [b]preview[/b] your message.

If for some reason you post your message without previewing and it is still incorrect you have the option to edit your posts for a few hours after you submit it. Please use these features of daniweb to keep your posts clean.

Try it one more time...[code ] tags inside of a

or . Try one more time. After you have entered your code click "GO ADVANCED" and [b]preview[/b] your message.

If for some reason you post your message without previewing and it is still incorrect you have the option to edit your posts for a few hours after you submit it. Please use these features of daniweb to keep your posts clean.

Try it one more time...[noparse ]. Try one more time. After you have entered your code click "GO ADVANCED" and preview your message.

If for some reason you post your message without previewing and it is still incorrect you have the option to edit your posts for a few hours after you submit it. Please use these features of daniweb to keep your posts clean.

Try it one more time...

I think you want to try a query like this

SELECT Count(*) FROM Orders 
WHERE signNumber = ? 
(AND ? BETWEEN fromdate and todate 
Or ? BETWEEN fromdate AND todate)

You need to use the OR condition or else both conditions have to be met when you want it to pull records if either condition is met.

Cgyrob
Please writte the full code from the try scoop to ex please

This article has been dead for over six months. Start a new discussion instead.