110,536
社区成员
发帖
与我相关
我的任务
分享
[WebMethod(Description="添加")]
public int Add(string id,string name,string title,string depar,string ass)
{
SqlConnection conn = new SqlConnection("hisdbConnectionString");
conn.Open();
string sql = "intsert into Doctor(dID,dName,Title,Department,Assistment) values(@dID,@dName,@Title,@Department,@Assistment)";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlParameter d = new SqlParameter("@dID", id);
cmd.Parameters.Add(d);
SqlParameter n= new SqlParameter("@dName", name);
cmd.Parameters.Add(n);
SqlParameter t = new SqlParameter("@Title", title);
cmd.Parameters.Add(t);
SqlParameter e = new SqlParameter("@Department", depar);
cmd.Parameters.Add(e);
SqlParameter a = new SqlParameter("@Assistment", ass);
cmd.Parameters.Add(a);
int result = cmd.ExecuteNonQuery();
conn.Close();
cmd.Dispose();
return result;
}
[WebMethod(Description = "更新")]
public int upda(string id, string name, string title, string depar, string ass)
{
SqlConnection conn = new SqlConnection("hisdbConnectionString");
conn.Open();
string sql = "update Doctor set dName=@dName,Title=@Title,Department=@Department,Assistment=@Assistment where dID=@dID";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlParameter d = new SqlParameter("@dID", id);
cmd.Parameters.Add(d);
SqlParameter n = new SqlParameter("@dName", name);
cmd.Parameters.Add(n);
SqlParameter t = new SqlParameter("@Title", title);
cmd.Parameters.Add(t);
SqlParameter e = new SqlParameter("@Department", depar);
cmd.Parameters.Add(e);
SqlParameter a = new SqlParameter("@Assistment", ass);
cmd.Parameters.Add(a);
int result = cmd.ExecuteNonQuery();
conn.Close();
cmd.Dispose();
return result;
}
[WebMethod(Description = "删除")]
public int del(string id)
{
SqlConnection conn = new SqlConnection("hisdbConnectionString");
conn.Open();
string sql = "delete * from Doctot where dID=@dID";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlParameter d = new SqlParameter("@dID", id);
cmd.Parameters.Add(d);
int result = cmd.ExecuteNonQuery();
conn.Close();
cmd.Dispose();
return result;
}
<body>
<form id="form1" runat="server">
<div style="height: 433px; width: 670px">
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
编号:<asp:TextBox ID="txt_1" runat="server"></asp:TextBox>
<br />
姓名:<asp:TextBox ID="txt_2" runat="server" ></asp:TextBox>
<br />
职称:<asp:TextBox ID="txt_3" runat="server" ></asp:TextBox>
<br />
科室:<asp:TextBox ID="txt_4" runat="server" ></asp:TextBox>
<br />
科室:<asp:TextBox ID="txt_5" runat="server" ></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="添加" />
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="更新" />
<asp:Button ID="Button3" runat="server" onclick="Button3_Click" Text="删除" />
</div>
</form>
</body>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class _112 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string connstr = ConfigurationManager.ConnectionStrings["hisdbConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(connstr);
try
{
conn.Open();
SqlDataAdapter ad = new SqlDataAdapter("Select * from Doctor", conn);
DataSet ds = new DataSet();
ad.Fill(ds);
this.GridView1.DataSource = ds;
this.GridView1.DataBind();
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
}
catch { }
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
//SELECT [pID], [pName], [pSex], [pDep], [pClass] FROM [pPerson]
int selectIndex = this.GridView1.SelectedIndex;
txt_1.Text = this.GridView1.DataKeys[selectIndex]["dID"].ToString();
txt_1.Enabled = false;
GridViewRow gvrow = this.GridView1.SelectedRow;
txt_2.Text = gvrow.Cells[2].Text.ToString();
txt_3.Text = gvrow.Cells[3].Text.ToString();
txt_4.Text = gvrow.Cells[4].Text.ToString();
txt_5.Text = gvrow.Cells[5].Text.ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
localhost.WebService1 web=new localhost.WebService1();
web.Add(txt_1.Text, txt_2.Text, txt_3.Text, txt_4.Text, txt_5.Text);
}
protected void Button2_Click(object sender, EventArgs e)
{
localhost.WebService1 web = new localhost.WebService1();
web.upda(txt_1.Text, txt_2.Text, txt_3.Text, txt_4.Text, txt_5.Text);
}
protected void Button3_Click(object sender, EventArgs e)
{
localhost.WebService1 web = new localhost.WebService1();
web.del(txt_1.Text);
}
}