Here i am inserting the data using WebService:
First Add a folder in that folder add WebService.asmx
Default.aspx:
<form id="form1" runat="server">
<div>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
Name
</td>
<td>
<asp:TextBox ID="txtUserName" runat="server" />
</td>
</tr>
<tr>
<td>
Balance
</td>
<td>
<asp:TextBox ID="txtBalance" runat="server" />
</td>
</tr>
<tr>
<td>
City
</td>
<td>
<asp:TextBox ID="txtCity" runat="server" />
</td>
</tr>
<tr>
<td colspan="1">
<asp:Button ID="Button1" Text="Save" runat="server" OnClick="Save" />
</td>
</tr>
</table>
</div>
</form>
C#: Default.aspx.cs
protected void Save(object sender, EventArgs e)
{
InsertService obj = new InsertService();
string name = this.txtUserName.Text.Trim();
int balance = int.Parse(this.txtBalance.Text.Trim());
string city = this.txtCity.Text.Trim();
obj.Insert(name, balance, city);
}
Add this function in WebService:
[WebMethod]
public void Insert(string name, int balance, string city)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
string sqlStatment = "INSERT INTO Customers(CustomerName,balance,City) values(@Name,@Balance,@City)";
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(sqlStatment, con))
{
con.Open();
cmd.Parameters.AddWithValue("@Name", name);
cmd.Parameters.AddWithValue("@Balance", balance);
cmd.Parameters.AddWithValue("@City", city);
cmd.ExecuteNonQuery();
con.Close();
}
}
}
In this Sample you do not have to add reference cause Webservice is in same Project.
You have to Add WebService in App_Code folder like this

Then create one Insert WebMethod function in WebService. Then In Aspx page on Button Click event Create the Object of Service class like this:
WebService obj = new WebService();
string name = this.txtUserName.Text.Trim();
int balance = int.Parse(this.txtBalance.Text.Trim());
string city = this.txtCity.Text.Trim();
obj.Insert(name, balance, city);
WebService is the class name and Insert is the function name to which i am passing the parameters that have to be saved in Database. You have to write your Webservice class name properly otherwise it will give you error.
Thank You.