可以先写一个类,来访问数据,一切妥当了,复制,粘贴。WebService和普通程序的区别就在于方法前加了[WebMothed]属性

解决方案 »

  1.   

    我看别人写的一个方法,可是其中的"wsURL",不知道是什么意思,
    服务器代码:
    [WebMethod]
    public DataSet returnDataSet(string strSql)
    {
       SqlConnection custConn=new SqlConnection(ConfigurationSettings.AppSettings["wsURL"]) ;
    SqlDataAdapter custDA = new SqlDataAdapter(strSql, custConn);
    custConn.Open();
    DataSet ds=new DataSet();
    custDA.Fill(ds,"User");
    custConn.Close();
    return ds;
    }
    客户端代码为: private void button1_Click(object sender, System.EventArgs e)
    {
    DataSet ds1;
    localhost.Service1 ser1  =new localhost.Service1(); 
    ser1.Url=ClsWeb.strUrl;
    ds1= ser1.RtuDataSet("select * from User where [姓名]='"+this.textBox1.Text+"' AND [密码]='"+this.textBox2.Text+"'");
    try
    {
    if ((int)(ds1.Tables[0].Rows.Count)>0)
    { MessageBox.Show("是!");
    }
    else
    {
    MessageBox.Show("否!");
    }
    }
    catch
    {
    MessageBox.Show("失败!");
    }
    }
    不知道这么写对不对,请高手再指点一下!
      

  2.   

    ConfigurationSettings.AppSettings["wsURL"]) 
    到配置文件里面找。web.config