Home > Net >  WebService is used to implement the database operations (add delete modify)
WebService is used to implement the database operations (add delete modify)

Time:10-19

 
[the WebMethod (Description="add")]
Public int the Add (string id, string name, string title, string depar, string along)
{
SqlConnection conn=new SqlConnection (" hisdbConnectionString ");
Conn. The 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. The Parameters. The Add (d);
SqlParameter n=new SqlParameter (" @ dName ", name);
CMD. The Parameters. The Add (n);
The SqlParameter t=new SqlParameter (" @ the Title, "the Title);
CMD. The Parameters. The Add (t);
SqlParameter e=new SqlParameter (" @ Department, "depar);
CMD. The Parameters. The Add (e);
SqlParameter a=new SqlParameter (" @ Assistment ", along);
CMD. The Parameters. The Add (a);
int result=cmd.ExecuteNonQuery();
Conn. Close ();
CMD. The Dispose ();
return result;
}
[the WebMethod (Description="update")]
Public int upda (string id of the string name, string title, string depar, string along)
{
SqlConnection conn=new SqlConnection (" hisdbConnectionString ");
Conn. The 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. The Parameters. The Add (d);
SqlParameter n=new SqlParameter (" @ dName ", name);
CMD. The Parameters. The Add (n);
The SqlParameter t=new SqlParameter (" @ the Title, "the Title);
CMD. The Parameters. The Add (t);
SqlParameter e=new SqlParameter (" @ Department, "depar);
CMD. The Parameters. The Add (e);
SqlParameter a=new SqlParameter (" @ Assistment ", along);
CMD. The Parameters. The Add (a);
int result=cmd.ExecuteNonQuery();
Conn. Close ();
CMD. The Dispose ();
return result;
}
[the WebMethod (Description="delete")]
Public int del (string id)
{
SqlConnection conn=new SqlConnection (" hisdbConnectionString ");
Conn. The Open ();
String SQL="delete * from Doctot where dID=@ dID";
SqlCommand CMD=new SqlCommand (SQL, conn);
SqlParameter d=new SqlParameter (" @ dID ", id);
CMD. The Parameters. The Add (d);
int result=cmd.ExecuteNonQuery();
Conn. Close ();
CMD. The Dispose ();
return result;
}

Create a web service do not know how to call these methods,
 & lt; body> 


Number: & lt; Asp: TextBox ID="txt_1" runat="server" & gt;

Name: & lt; Asp: TextBox ID="txt_2" runat="server" & gt;

Title: & lt; Asp: TextBox ID="txt_3" runat="server" & gt;


Department: & lt; Asp: TextBox ID="txt_4" runat="server" & gt;

Department: & lt; Asp: TextBox ID="txt_5" runat="server" & gt;






 using System; 
Using System. Collections. Generic;
Using System. Linq;
Using System. The Web;
Using System. Web. UI.
Using System. Web. UI. WebControls;
Using System. The Data;
Using System. The Data. SqlClient.
Using System. The Configuration;


Public partial class _112: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
String connstr=ConfigurationManager. ConnectionStrings [r]. "hisdbConnectionString" ConnectionString;
SqlConnection conn=new SqlConnection (connstr);
Try
{
Conn. The Open ();
SqlDataAdapter AD=new SqlDataAdapter (" Select * from Doctor ", conn);
The DataSet ds=new DataSet ();
A. The Fill (ds);
Enclosing GridView1. The 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] [r]. "dID" the ToString ();
Txt_1. Enabled=false;
GridViewRow gvrow=this. GridView1. SelectedRow;
Txt_2. Text=gvrow. Cells [2]. The Text. The ToString ();
Txt_3. Text=gvrow. Cells [3]. The Text. The ToString ();
Txt_4. Text=gvrow. Cells [4]. The Text. The ToString ();
Txt_5. Text=gvrow. Cells [5]. The Text. The ToString ();



}

Protected void Button1_Click (object sender, EventArgs e)
{

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related