Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

c# - 'int' does not contain a definition and no extension method

I am facing the below error

'int' does not contain a definition for 'LeaveType' and no extension method 'LeaveType' accepting a first argument of type 'int' could be found (are you missing a using directive or an assembly reference?)

here is my code :

public DataSet GetLeaveRecord(int empID)
{
    DataSet ds = new DataSet();
    try
    {
        SqlCommand cmd = new SqlCommand("[p_GetLeaveRecord_LMS]", conn);
        cmd.CommandType = CommandType.StoredProcedure;
        SqlDataAdapter adapter = new SqlDataAdapter(cmd);
        cmd.Parameters.AddWithValue("@LeaveType", empID.LeaveType);
        cmd.Parameters.AddWithValue("@IdEmployee", empID.EmployeeId);
        cmd.Parameters.AddWithValue("@DateFrom", empIDd.DateFrom);
        cmd.Parameters.AddWithValue("@DateTo ", empID.DateTo);
        cmd.Parameters.AddWithValue("@Reason", empID.Reason);
        if (conn.State == ConnectionState.Closed)
        {
            conn.Open();
        }
        adapter.Fill(ds);
    }
    catch (Exception e)
    {
        throw e;
    }
    finally
    {
        if (conn.State == ConnectionState.Open)
        {
            conn.Close();
        }
    }
    return ds;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You are passing empID as an int type parameter and later you are using it as a type in your parameters. For example.

 cmd.Parameters.AddWithValue("@LeaveType", empID.LeaveType);

I believe you have to pass your object probably of EmployeeLeave type in your method

GetLeaveRecord(int empID)

Or you may get your object based on the ID in your method and then use that in your parameters


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...