亲爱的,这是我的代码,一切都很好,但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;
}
}
}
}
答案 0 :(得分:0)
谢谢亲爱的,但我这样修好了我的事:
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;
}
}
}