3-->我们首先要引用Web服务的地址,我们找到刚才发布Web服务的地址,http://localhost:1666/Infos.asmx,由于我是直接在我以前做的基础上做的,上一个Web服务是新建的,里面方法什么的也没有写,所以我就贴了我做好了Web地址。
namespace WindowsFormsApplication14
{
public partial class Form1 : Form
{
private ServiceReference.InfosSoapClient ws; //这样就省得在每一个方法中都实例化了
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“dB_UserSystemDataSet.TB_UserInfo”中。您可以根据需要移动或删除它。
//this.tB_UserInfoTableAdapter.Fill(this.dB_UserSystemDataSet.TB_UserInfo);
//LoadData();
ws = new ServiceReference.InfosSoapClient(); //同上
}
private void button1_Click(object sender, EventArgs e)
{
string UserID = txtUserID.Text.Trim();
string UserName = txtUserName.Text.Trim();
string UserSex = this.comboBox2.Text;
string UserAge = txtUserAge.Text;
string UserPassword = txtUserPassword.Text;
string UserType = this.comboBox3.Text;
string errorinfo = "";
if (ws.add(txtUserID.Text, txtUserName.Text, this.comboBox2.Text, txtUserAge.Text, txtUserPassword.Text, this.comboBox3.Text, ref errorinfo))
{
MessageBox.Show("注册成功" + errorinfo);
}
else
{
MessageBox.Show("注册失败" + errorinfo);
}
}
private void button2_Click(object sender, EventArgs e)
{
int UserAge=0;
try
{
int.Parse(txtUserAge.Text);
UserAge = Convert.ToInt32(txtUserAge.Text);
}
catch (Exception)
{
MessageBox.Show("输入不正确", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
return;
}
string errorinfo = "";
if (ws.update(txtUserID.Text,txtUserName.Text,this.comboBox2.Text,txtUserAge.Text,txtUserPassword.Text,this.comboBox3.Text,ref errorinfo))
{
MessageBox.Show("更新成功" );
}
else
{
MessageBox.Show("更新失败" );
}
}
private void button3_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("确定要删除吗?", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (result == System.Windows.Forms.DialogResult.OK)
{
string errorinfo = "";
if (ws.delete(txtUserID.Text, ref errorinfo))
{
MessageBox.Show("删除成功" + er