Click here to Skip to main content
15,889,834 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my service


C#
public List<chartentity> chartAnalysis(string data1, string data2, string loc)
       {
           string str1 = data1;
           string str2 = data2;
           string location = loc;
           List<chartentity> chartinfo = new List<chartentity>();
           DataSet ds4 = new DataSet();
           using (SqlConnection con = new SqlConnection("Data Source=xxxx;User Id=sxxxa;Password=xxx;DataBase=xxx"))
           {
               using (SqlCommand cmd = new SqlCommand())
               {
                   //cmd.CommandText = "exec sp_AreaWiseSales_DashBoard_REP '2012-02-02','2012-07-08',1";
                   cmd.CommandText = " exec sp_AreaWiseSales_DashBoard_REP '" + str1 + "' ,'" + str2 + "','" + location + "'";
                   cmd.Connection = con;
                   using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                   {
                       da.Fill(ds4);
                   }
               }
               con.Close();
           }
           if (ds4 != null)
           {
               if (ds4.Tables.Count &gt; 0)
               {
                   if (ds4.Tables[0].Rows.Count &gt; 0)
                   {
                       foreach (DataRow dr in ds4.Tables[0].Rows)
                       {
                           chartinfo.Add(new ChartEntity { Name = dr["AreaName"].ToString(), value = Convert.ToInt32(dr["Amt"]) });
                       }
                   }
               }
           }

           return chartinfo;
       }

This is my asp.net code
HTML
$.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "Services/New.asmx/chartAnalysis",  //I am calling the service here.But it is not call to the method how can i call it.There is another way to call the service method 
                    
                    
                    data: JSON.stringify({ data1: "2012-02-05", data2: "2012-05-05", loc: "1" }),
                    
                    totaldata: "{},{}",
                    dataType: "json",
                    success: function (Result) {
                        Result = Result.d;
                        var data = [];

                        for (var i in Result) {
                            var serie = new Array(Result[i].Name, Result[i].value);
                            data.push(serie);
                        }
                        DreawChart3(data);
                    },
});


How can i solve this problem
Posted
Updated 16-Jul-15 3:23am
v3
Comments
Richard Deeming 16-Jul-15 12:05pm    
Your service code is vulnerable to SQL Injection[^].

NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

1 solution

You need to mark your method as being a WebMethod. Examples can be found here[^]

If you still have problems then use the browser's dev tools (f12) or something like Fiddler to examine the network traffic to reveal any error messages etc.
 
Share this answer
 

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