My code is use.........Iservice1.CS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace WcfServiceInsertStudent
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{
[OperationContract]
bool InsertStudent(StudentDetails std_det);
// TODO: Add your service operations here
}
// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class StudentDetails
{
int id;
string name;
[DataMember]
public int Id
{
get { return id; }
set { value = id; }
}
[DataMember]
public string Name
{
get { return name; }
set { value = name; }
}
}
}
and Service1.svc.cs................
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Data.SqlClient;
namespace WcfServiceInsertStudent
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class Service1 : IService1
{
public bool InsertStudent(StudentDetails std_det)
{
bool result = false;
SqlConnection con = new SqlConnection("Data Source=shail-PC;Initial Catalog=College;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("Insert into UserTab1(Name)values(@Name)", con);
cmd.Parameters.AddWithValue("@Name", std_det.Name);
result = Convert.ToBoolean(cmd.ExecuteNonQuery());
con.Close();
return result;
}
}
}
and my aspx.cs......code is
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ServiceReference1;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
ServiceReference1.Service1Client obj = new ServiceReference1.Service1Client();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnsub_Click(object sender, EventArgs e)
{
StudentDetails std_det = new StudentDetails();
std_det.Name = txtname.Text;
obj.InsertStudent(std_det);
}
}
My table is.............
Id int (pk) not null,
Name varchar(50) not null
and error come in service1.svc.cs
The parameterized query '(@Name nvarchar(4000))Insert into UserTab1(Name)values(@Name)' expects the parameter '@Name', which was not supplied.
plz help me