Click here to Skip to main content
15,883,852 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
This is my webmethod

[WebMethod]
public void insertidentry(int wcode, int mcode, int ccode, int dr, int evcode, string loccode, string lotcode,string houseno,string houseadd,string postion,string latitude,string longitude,string altitude,string accuracy,string phoneno,string hhfname,string hhlname,string hhmname,string ivcode,string ivdate,string sttime,string endtime,int hhno,int code,string edate,string hhid)
{
string conStr = WebConfigurationManager.ConnectionStrings["SQLDbConnection"].ConnectionString;

using (SqlConnection conn = new SqlConnection(conStr))
{
string sql = string.Format(@"Insert into IdMaster(WCode,MCode,CCode,DR,EVCode,LocCode,LotCode,HouseNo,HouseAdd,Postioning,Latitude,Longitude,Altitude,Accuracy,PhoneNo,HHFname,HHLname,HHMname,IVCode,IVdate,StTime,EndTime,HHNo,ICode,Edate,HHID) values (" + wcode
+"," + mcode + "," + ccode + "," + dr + "," + evcode + ",'" + loccode + "','"+ lotcode + "','" + houseno + "','" + houseadd + "','" + postion + "','" + latitude + "','" + longitude + "','" + altitude + "','" + accuracy + "','" + phoneno
+ "','" + hhfname + "','" + hhlname + "','" + hhmname + "','" + ivcode + "','" + ivdate + "','" + sttime + "','" + endtime + "'," + hhno + "," + code + " ,'" + edate + "','" + hhid + "') ");
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = sql;
cmd.CommandType = CommandType.Text;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
cmd = null;
}
}


I want to send my sqlite data to web service so that the data inserted to remote sqlserver.
Posted
Comments
Sinisa Hajnal 28-Jan-15 2:40am    
And what is the problem?

Also, since you're using string.format, replace all that + "," + with normal sql and placeholders and simply list the variables in string formats argument list. It will be much easier to read. Also, use code tag on the post so it gets formatted. Finally, I would suggest to move the insert into stored procedure, makes sql injection attacks much harder.
Sandip Paul 491984 28-Jan-15 3:07am    
i am new to android .i just want to send all the sqlite data to ms sql server by onclick listner of a button.'" + + "' are used to pass the parameters.can you tell me how to implement this?
Sinisa Hajnal 28-Jan-15 6:11am    
I can't since I don't know your database. If you want to send the file of the database, you can easily google it. If you need to send DATA from the database, then you select what you need, package in whatever format your service accepts and you're done.
Sinisa Hajnal 28-Jan-15 6:13am    
My comment on String.Format:
Which do you find more readable?
String.Format("INSERT INTO table (id, name) VALUES ({0}, '{1}')", id, name)
OR
String.Format("INSERT INTO table (id, name) VALUES (" + id.ToString() + ", '" + name + "')")

Since you have string concatenation like this, why use string.Format at all?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900