Durga
Durga

Reputation: 1303

Fetching data for particular Month and year

I tried Query(given below in code) But it is showing me this error

No value given for one or more required parameters.

but while debugging I am passing date as this

string monthYY = dateTimePickerMonth.Value.ToString("M-yy");

So what is the right format to check it ,how can I do it ?

Code for Query

public int GetDrID_MonthWise(string DrName,string monthYY,int refDrID)
        {
            int data = 0;
            try
            {
                string sql = "Select d.DoctorID From Doctor_Master d where d.LastName + ' ' + d.FirstName = '" + DrName + "' AND Patient_registration.RegDate='" + monthYY + "' AND Patient_registration.DoctorID=" + refDrID;
                cmd = new OleDbCommand(sql, acccon);
                rs = cmd.ExecuteReader();
                while (rs.Read())
                {
                    data = Convert.ToInt32(rs[0]);
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message.ToString());
            }
            return data;
        }

Upvotes: 1

Views: 247

Answers (2)

user2843336
user2843336

Reputation: 44

I'm not sure exactly how you are passing your parameters but you need to specify values for all three of your parameters listed

public int GetDrID_MonthWise(string DrName,string monthYY,int refDrID)

Upvotes: 0

HansUp
HansUp

Reputation: 97101

This piece of your SQL statement informs the db engine Doctor_Master is the data source:

From Doctor_Master d

However, the WHERE clause refers to 2 fields which are not present in Doctor_Master:

  1. Patient_registration.RegDate
  2. Patient_registration.DoctorID

I'm unsure what you actually need. My hunch is you should INNER JOIN those tables. But I think you should design and test the query in Access, leaving c# out of the picture until after you have the Access query working as you wish.

Upvotes: 2

Related Questions