名称' GetData(cmd)'在当前上下文中不存在

时间:2016-08-02 04:38:05

标签: c# asp.net

我有这个错误"名称' GetData'在当前上下文中不存在"。我试图声明getdata()函数,但它仍然有错误。

public partial class v2_kradescription : System.Web.UI.Page
{
private String conn = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

我的c#代码已经有了

 protected void Page_Load(object sender, EventArgs e)
{
    if(!IsPostBack)
    {
        BindData();
    }
}

在这里,我使用了getdata()

protected void BindData()
{
    string conn = "select kr_id,kr_position,kr_description from tblKRAObjective";
    SqlCommand cmd = new SqlCommand(conn);
    GridView1.DataSource = GetData(cmd);
    GridView1.DataBind();

}

protected void AddNewJob(object sender, EventArgs e)
{
    if (e.Equals("btnAdd"))
    {
        string jid = ((TextBox)GridView1.FooterRow.FindControl("txtid")).Text;
        string jposition = ((TextBox)GridView1.FooterRow.FindControl("txtposition")).Text;
        string jdescription = ((TextBox)GridView1.FooterRow.FindControl("txtdescription")).Text;

        SqlConnection con = new SqlConnection(conn);
        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = "insert into tblJobDescription (j_id, j_position, j_description) " + "values(@j_id, @j_position, @j_description);" + "select j_id,j_position,j_description from tblJobDescription";
        cmd.Parameters.Add("@j_id", SqlDbType.VarChar).Value = jid;
        cmd.Parameters.Add("@j_position", SqlDbType.VarChar).Value = jposition;
        cmd.Parameters.Add("@j_description", SqlDbType.VarChar).Value = jdescription;
        GridView1.DataSourceID = GetData(con);
        GridView1.DataBind();
    }
}

protected void EditDescription(object sender, GridViewEditEventArgs e)
{
    GridView1.EditIndex = e.NewEditIndex;
    BindData();
}

protected void CancelEdit(object sender, GridViewCancelEditEventArgs e)
{
    GridView1.EditIndex = -1;
    BindData();
}

protected void UpdateDescription(object sender, GridViewUpdateEventArgs e)
{

    string jid = ((TextBox)GridView1.FooterRow.FindControl("txtkr_id")).Text;
    string jposition = ((TextBox)GridView1.FooterRow.FindControl("txtkr_position")).Text;
    string jdescription = ((TextBox)GridView1.FooterRow.FindControl("txtkr_description")).Text;

    SqlCommand con = new SqlCommand(conn);
    SqlCommand cmd = new SqlCommand();

    cmd.CommandType = CommandType.Text;
    cmd.CommandText = "update tblJobDescription set j_id=@j_id,j_position=@j_position where j_id=@j_id "; 
    cmd.Parameters.Add("@j_id", SqlDbType.Int).Value = jid;
    cmd.Parameters.Add("@j_position", SqlDbType.Int).Value = jposition;
    cmd.Parameters.Add("@j_description", SqlDbType.Int).Value = jdescription;

    GridView1.EditIndex = -1;
   GridView1.DataSourceID = GetData(cmd); 
    GridView1.DataBind();

}

protected void DeleteDescription(object sender, EventArgs e)
{
    LinkButton lnkRemove = (LinkButton)sender;
    SqlConnection con = new SqlConnection(conn);
    SqlCommand cmd = new SqlCommand();
    cmd.CommandType = CommandType.Text;
    cmd.CommandText = " delete from tblJobDescription where j_id=@j_id";
    cmd.Parameters.Add("@j_id", SqlDbType.VarChar).Value = lnkRemove.CommandArgument;
    GridView1.DataSource = GetData(cmd);
    GridView1.DataBind();
}

protected void OnPaging(object sender, GridViewPageEventArgs e)
{
    BindData();
    GridView1.PageIndex = e.NewPageIndex;
    GridView1.DataBind();
}

protected void btnPreview_Click(object sender, EventArgs e)
{
            Response.Redirect("kra_pdf.aspx");
}

protected void btnSubmit_Click(object sender, EventArgs e)
{
    if (Page.IsValid)
    {

        string jicno = (string)(Session["s_icno"]);
        string jobid = "";
        string jobdescription = "";
        string jobposition = "";

        try
        {

            string query = "InsertJobDescription";


            // get requester name, companyid, primary appraiser of requester

            String queryA = "SELECT kr_id, kr_description, kr_position FROM tblKRAObjective WHERE s_icno = '" + jicno + "'  ";
            SqlCommand cmdA = new SqlCommand(conn);
            SqlDataReader drA = cmdA.ExecuteReader();

            if (drA.Read())
            {
                jobid = drA["j_id"].ToString();
                jicno = drA["j_icno"].ToString();
                jobdescription = drA["j_descpription"].ToString();
                jobposition = drA["j_position"].ToString();
            }
            drA.Close();

            SqlCommand cmd1 = new SqlCommand(conn);
            cmd1.CommandType = CommandType.StoredProcedure;

            cmd1.Parameters.Add("@j_icno", SqlDbType.NVarChar).Value = jicno.ToString();
            cmd1.Parameters.Add("@j_description", SqlDbType.NVarChar).Value = jobdescription.ToString();
            cmd1.Parameters.Add("@j_position", SqlDbType.NVarChar).Value = jobposition.ToString();

            cmd1.ExecuteNonQuery();

         }
                catch (Exception ex)
        {
            lblMsg.Text = ex.Message; //" Error while saving the record.";  
        }
        Response.Redirect("kra_dashboard.aspx");
    }
}

但无论如何,我收到了错误

 The name 'GetData' does not exist in the current context

所以,我的错误在哪里?

0 个答案:

没有答案