Web Services 找不到类型或命名空间GlobalVar

u5i3ibmn  于 2022-11-15  发布在  其他
关注(0)|答案(1)|浏览(193)

请亲爱的,这是我的代码,一切都很好,但GlobalVar没有被宣布任何建议。

[WebMethod(MessageName = "OpenAccount", Description = "This method is to add new account")]
    [System.Xml.Serialization.XmlInclude(typeof(ContactResult))]

    public ContactResult openaccount(String FullName, String Phone)
    {
        ContactResult cr = new ContactResult();
        **GlobalVar var = new GlobalVar();**

        try
        {
            using (SqlConnection openconn = new SqlConnection(var.connectionstring))
            {
                string save = "INSERT into AndroidContact (AndroidContactName,AndroidContactPhone) VALUES ('" + FullName + "' ,'" + Phone + "')";
                using (SqlCommand query = new SqlCommand(save))
                {
                    query.Connection = openconn;
                    query.Parameters.Add("@AndroidContactName", SqlDbType.NVarChar, 50).Value = FullName;
                    query.Parameters.Add("@AndroidContactPhone", SqlDbType.NVarChar, 50).Value = Phone;

                    openconn.Open();
                    query.ExecuteNonQuery();
                    openconn.Close();
                }
            }

            cr.ErrorID = 0;
            cr.ErrorMessage = "Contact Added";
            return cr;
        } 
            catch (Exception ex){

                cr.ErrorID = 1;
                cr.ErrorMessage = ex.Message;
                return cr;
        }
    }
}

}

mwg9r5ms

mwg9r5ms1#

谢谢,但我的是这样的:

public class WebService1 : System.Web.Services.WebService
    {

        [WebMethod(MessageName = "OpenAccount", Description = "This method is to add new account")]
        [System.Xml.Serialization.XmlInclude(typeof(ContactResult))]

        public ContactResult openaccount(String FullName, String Phone)
        {
            ContactResult cr = new ContactResult();
            SqlConnection Connection = new SqlConnection();
            try
            {
                Connection.ConnectionString = ConfigurationManager.ConnectionStrings["webConnectionString"].ToString();
                Connection.Open();
                SqlCommand save = new SqlCommand ("INSERT into AndroidContact (AndroidContactName,AndroidContactPhone) VALUES ('" + FullName + "' ,'" + Phone + "')",Connection);
                
                save.ExecuteNonQuery();

                cr.ErrorID = 0;
                cr.ErrorMessage = "Contact Added";
                return cr;
            }
            catch (Exception ex)
            {

                cr.ErrorID = 1;
                cr.ErrorMessage = ex.Message;
                return cr;
            }
        }
    }

相关问题