新手问题 代码问题 希望大家帮忙
- C# code
using System;using System.Data;using System.Web;using System.Collections;using System.Web.Services;using System.Web.Services.Protocols;using System.Data.SqlClient;/// <summary>/// WebService 的摘要说明/// </summary>[WebService(Namespace = "http://tempuri.org/")][WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]public class WebService : System.Web.Services.WebService { public WebService () { //如果使用设计的组件,请取消注释以下行 //InitializeComponent(); } [WebMethod] public string HelloWorld() { return "Hello World"; } public void ExcuteSql(string strSql) { SqlConnection conn = new SqlConnection(); conn.ConnectionString = "Server=localhost;" + "Database=Hospital;" + "Integrated Security=true;"; conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = strSql; cmd.ExecuteNonQuery(); conn.Close(); conn.Dispose(); } public DataTable ExcuteSelect(string strSql) { SqlConnection conn = new SqlConnection(); conn.ConnectionString = "Server=localhost;" + "Database=Hospital;" + "Integrated Security=true;"; conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = strSql; SqlDataAdapter adapter = new SqlDataAdapter(strSql,conn); DataSet ds = new DataSet(); adapter.Fill(ds, "table"); return ds.Tables["table"]; } public bool HasName(string strSql) { SqlConnection conn = new SqlConnection(); conn.ConnectionString = "Server=localhost;" + "Database=Hospital;" + "Integrated Security=true;"; conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = strSql; SqlDataReader reader = cmd.ExecuteReader(); return reader.Read(); }}
- C# code
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class EditInformation : System.Web.UI.Page
{
public string strSql;
WebService webS = new WebService();
public DataTable dr;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserLevel"] == null || Session["UserLevel"].ToString() != "User")
{
Response.Redirect("Error.aspx?");
}
if (Page.IsPostBack)
{
strSql = "selecet * from Enterprises_Info where Ent='" + Session["UserID"].ToString() + "';";
dr = webS.ExcuteSelect(strSql);
this.lbUser.Text=dr.Rows[0]["Ent_User"].ToString();
this.tbPsw.Text = dr.Rows[0]["Ent_Psw"].ToString();
this.tbName.Text = dr.Rows[0]["Ent_Name"].ToString();
this.lbNO.Text=dr.Rows[0]["Ent_Code"].ToString();
this.ddtype.SelectedValue = dr.Rows[0]["Ent_Economictype"].ToString();
this.ddInd.SelectedValue = dr.Rows[0]["Ent_Industry"].ToString();
this.ddScale.SelectedValue = dr.Rows[0]["Ent_Scale"].ToString();
this.tbDis.Text = dr.Rows[0]["Ent_District"].ToString();
this.tbPosNO.Text = dr.Rows[0]["Ent_Postalcode"].ToString();
this.tbMail.Text = dr.Rows[0]["Ent_Mail"].ToString();
this.tbFor.Text = dr.Rows[0]["Ent_For"].ToString();
this.tbPho.Text = dr.Rows[0]["Ent_Phonecode"].ToString();
this.tbAdd.Text = dr.Rows[0]["Ent_Address"].ToString();
this.tbRem.Text = dr.Rows[0]["Ent_Remarks"].ToString();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if(Page.IsValid)
{
string strPsw=this.tbPsw.Text;
string strName=this.tbName.Text;
string strType=this.ddtype.SelectedValue;
string strInd=this.ddInd.SelectedValue;
string strScale=this.ddScale.SelectedValue;
string strDis=this.tbDis.Text;
string strPos=this.tbPosNO.Text;
string strMail=this.tbMail.Text;
string strFor=this.tbFor.Text;
string strPho=this.tbPho.Text;
string strAdd=this.tbAdd.Text;
string strRem=this.tbRem.Text;
strSql="update Enterprises_Info set Ent_Psw='"+tbPsw+"',Ent_Name='"+strName+"',Ent_Economictype='"+strType+"',Ent_Industry='"+strInd+"',Ent_Scale='"+strScale+"',Ent_District='"+strDis+"',Ent_Postalcode='"+strPos+"',Ent_Mail='"+strMail+"',Ent_For='"+strFor+"',Ent_Phonecode='"+strPho+"',Ent_Address='"+strAdd+"',Ent_Remarks='"+strRem+"',Ent_Lawstime='"+DateTime.Now+"' where Ent_ID='"+Session["UserID"].ToString()+"';";
webS.ExcuteSql(strSql);
Response.Redirect("");
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("EditInformation.aspx");
}
}
[解决办法]
public void ExcuteSql(string strSql)
{
==
[WebMethod]
public void ExcuteSql(string strSql)
{