Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
note it is windows applciation.

I am suing msaccess database.

Database Design as follows;

table name Leave

Faculty Code   text
Day            text



Screen Name Common holidays.
Design as follows;
Faculty Code   combobox
Day            Combobox



In Combobbox all faculty code are retrieved from the another table)
in Days manually typed in the coding Monday to Satruday.

In run mode design screen as follows;

select the faculty code from combobox and select the day from the combobox and save it in the database for all faculty code.



Database Design as follows;

Faculty Code    text
Available date  text


Screen Name Faculty Availability
Design screen as follows;

faculty code  Combobbox
Calendar(Month Calendar)
Datagridview.



In the combobox select the faculty code and select the month from the calendar selected month all dates will display in the datagridview.

in the datagridview, for that faculty code in selected month particular date is leave means that leave date is shown in different color in datagridview .

for that leave date storing in the leave table,checking whether for that faculty in the selected month any date is leave, when he leave that date is shown in different color in datagridiview.
that date is disable,cannot able to select that date.



in the run mode when i open, Faculty Availability screen
and select the faculty code from the combobox and select the month from the calendar,suppose for that month any date is leave from the faculty that date is shown in different color

simutaneously when i open Common holidays screen,


Show the error as follows;
unspecified error.

MY code Faculty Availability screen as follows in calerndar date changed event code as folows;

C#
private void Faculty_Available_Calendar_DateChanged(object sender, DateRangeEventArgs e)
     {

         if (cb_Faculty_Code.Text.ToString().Trim() == "")
         {
             MessageBox.Show("Please Select the Faculty Code", "Not Select", MessageBoxButtons.OK, MessageBoxIcon.Information);
             cb_Faculty_Code.Focus();
             return;
         }

         //selected month all dates  display in datagridiview

         DGVCalendar.Rows.Clear();
         DateTime dt1 = Faculty_Available_Calendar.SelectionStart;
         dt1 = new DateTime(dt1.Year, dt1.Month, 1);
         DateTime dt2 = dt1.AddMonths(1);
         int numDays = (dt2 - dt1).Days;
         if (DGVCalendar.RowCount < numDays)
         {
             DGVCalendar.RowCount = numDays;
         }

         int row = 0;
         while (dt1 < dt2)
         {
             DGVCalendar.Rows[row].Cells[1].Value = dt1.ToString("dd-MMM-yyyy");
             DGVCalendar.Rows[row].Cells[0].Value = true;  //All checkbox Checked Default

             DGVCalendar.Rows[row].Cells[0].Style.BackColor = Color.MistyRose;
             DGVCalendar.Rows[row].Cells[1].Style.BackColor = Color.MistyRose;
             DGVCalendar.Rows[row].Cells[2].Style.BackColor = Color.MistyRose;
             DGVCalendar.Rows[row].Cells[2].Style.ForeColor = Color.Green;

             if (dt1.DayOfWeek == DayOfWeek.Sunday)
             {
                 DGVCalendar.Rows[row].ReadOnly = true;
                 DGVCalendar.Rows[row].Cells[0].Value = false;
                 DGVCalendar.Rows[row].Cells[0].Style.BackColor = Color.Orange;
                 DGVCalendar.Rows[row].Cells[1].Style.BackColor = Color.Orange;
                 DGVCalendar.Rows[row].Cells[2].Style.BackColor = Color.Yellow;
                 DGVCalendar.Rows[row].Cells[2].Style.ForeColor = Color.Red;
                 DGVCalendar.Rows[row].Cells[2].Value = "Sunday";
             }

             // sql = "select Name from Tb_common_Holidays where Name = '" + cb_Faculty_Code.Text + "' and   Day = '" + DGVCalendar.Rows[row].Cells[1].Value.ToString() + "'";
             //sql = "select Name,Day from Tb_common_Holidays where Name = '" + cb_Faculty_Code.Text + "' and  Day = '" + Faculty_Available_Calendar.SelectionStart.ToString("dd") + "'";
             sql = "select Name from Tb_common_Holidays where Name = '" + cb_Faculty_Code.Text.ToString().Trim() + "' and   Day = '" + dt1.DayOfWeek.ToString().Trim() + "' ";
             dr = GFun.ReadAcessSql(sql);
             dr.Read();
             if (dr.HasRows == true)
             {
                 DGVCalendar.Rows[row].Cells[1].Style.BackColor = Color.Pink;
                 DGVCalendar.Rows[row].Cells[2].Style.ForeColor = Color.Brown;
                 DGVCalendar.Rows[row].Cells[2].Value = dt1.DayOfWeek.ToString();
             }
             dt1 = dt1.AddDays(1);
             row++;
         }
     }


what is the problem in my code?

Please help me,

when i run faculty availability screen and working, simutaneously when i open the common holidays screen that time error shows as follows;
unspecified error.

what is the problem?

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 25-Feb-13 21:11pm
v2
Comments
Prakash Thirumoorthy 26-Feb-13 3:21am    
exactly in which u got this error?

1 solution

The problem you are getting is here: "select Name from Tb_common_Holidays where Name = "
If you look at your table design, you don't have a column called "Name" - only "Faculty Code" and "Day", so when you try to select the "Name" is doesn't work. To make matters worse, "Name" is a reserved word in Access, so it is getting very, very confused about what you are trying to do and returning an "unspecified error" because it relay isn't sure what the problem is.

So change the SELECT statement to match your table definition, and the error should go away.

But...there are other things you should do here as well.
Firstly, do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead. This will probably mean changes to your ReadAcessSql method, so I can't show you how, but trust me: unless you do this, your best mate will destroy your database "to see what happens" when he types in your faculty code textbox...

Secondly, a TextBox.Text property is a string already, so calling ToString on it is both wasteful and makes your code look clumsy and unprofessional. You can also check for an empty string directly with
C#
if (string.IsNullOrWhiteSpace(cb_Faculty_Code.Text))
   {
   ...


Thirdly, stop using "magic numbers" in your code! Replace the absolute numbers in your Cells[n] references with named constants - it makes your code both more readable, and easier to maintain.
 
Share this answer
 
Comments
Joezer BH 26-Feb-13 4:03am    
5+
boogac 26-Feb-13 7:31am    
5++;

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