hello friends,
iam developing one android application, but i want to insert a values into mysql using wcf services
please suggest me
thanking you.
here is my code:
android app code:
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("fullname",s1));
nameValuePairs.add(new BasicNameValuePair("bloodgroup",s6));
nameValuePairs.add(new BasicNameValuePair("dob",s3));
nameValuePairs.add(new BasicNameValuePair("gender",s7));
nameValuePairs.add(new BasicNameValuePair("phoneno",s2));
nameValuePairs.add(new BasicNameValuePair("emailid",s4));
nameValuePairs.add(new BasicNameValuePair("fulladdress",s5));
String url = "http://localhost:49910/Service1.svc";
HttpClient client = new DefaultHttpClient();
HttpResponse response;
JSONObject json = new JSONObject();
HttpPost post = new HttpPost(url);
json.put("fullname",s1);
json.put("bloodgroup",s6);
json.put("dob",s3);
json.put("gender",s7);
json.put("phoneno",s2);
json.put("emailid",s4);
json.put("fulladdress",s5);
StringEntity se = new StringEntity(json.toString());
se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE,"application/json"));
post.setEntity(se);
response = client.execute(post);
}
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 MySql.Data;
using MySql.Data.MySqlClient;
using System.Web.Services.Description;
using System.Data;
using System.Runtime.Serialization.Json;
using Newtonsoft.Json;
namespace bloodservices
{
public class Service1 : IService1
{
MySqlConnection con = new MySqlConnection("datasource=localhost;database=blood_donar;userid=root;password=vishwas7890");
MySqlCommand cmd;
string Message;
public string InsertUserDetails(UserDetails userInfo)
{
cmd = new MySqlCommand("insert into registration_tab(fullname,bloodgroup,dob,gender,phoneno,emailid,fulladdress) values(@fullname,@bloodgroup,@dob,@gender,@phoneno,@emailid,@fulladdress)", con);
con.Open();
cmd.Parameters.AddWithValue("@fullname", userInfo.Fullname);
cmd.Parameters.AddWithValue("@bloodgroup", userInfo.Bloodgroup);
cmd.Parameters.AddWithValue("@dob", userInfo.Dob);
cmd.Parameters.AddWithValue("@gender", userInfo.Gender);
cmd.Parameters.AddWithValue("@phoneno", userInfo.Phoneno);
cmd.Parameters.AddWithValue("@emailid", userInfo.Emailid);
cmd.Parameters.AddWithValue("@fulladdress", userInfo.Fulladdress);
if (result == 1)
{
Message=" Details inserted successfully";
}
else
{
Message = " Details not inserted successfully";
}
con.Close();
return Message;
}
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 bloodservices
{
[ServiceContract]
public interface IService1
{
string InsertUserDetails(UserDetails userInfo);
}