Hi,
I have a got a web page that has a javascript file with ajax call to a web method. The web method contains a call to database using stored procedure with parameter. If the sent parameter matches, the data will be returned in a array format. My question is how do I pass the textbox value to this ajax call and get the cmd.Parameters.Add in the execution of the stored procedure to retrieve the result.
These is my code : - I am actually passing the date in the textbox txtDate as the parameter.
- ASPX page : -
<div><b>Date:</b> <asp:TextBox ID="txtDate" runat="server" ClientIDMode="Static"/><asp:Button ID="Button1" runat="server" Text="OK" OnClick="Button1_Click"/></div>
JS file $.ajax({ alert: ("It has started"), type: "post", url: "BarChart.asmx/CreateSubListTable", // data: "{ firstName: 'Aidy', lastName: 'F' }", contentType: "application/json; charset=utf-8", dataType: "json", success: function (res, textStatus) { var data1 = JSON.parse(res.d); console.log(data1); createbarchart(data1); //pass the array of data1 into a function //drawdoughnutchat(data1); // console.log("Function called"); }, error: function (xhr, textStatus, error) { console.log(xhr.responseText); console.log(xhr.statusText); console.log(textStatus); console.log(error); } })
3. SQL stored procedure in BarChart.asmxpublic List<DenDate> AddListintoParentArr() { List<DenDate> resultslistden = new List<DenonDate>(); using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = con; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "CheckforDateinTablesRough"; //cmd.Parameters.Add("@Value", SqlDbType.Date).Value = DateTime.ParseExact(LabelDate.Text, "dd/MM/yyyy", null); con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { DenDate results = new DenDate { RunningJobTblName = rdr["TableName"].ToString(), TblNameShort = rdr["ShortForm"].ToString(), JobOrderName = rdr["JobOrderName"].ToString(), DeeProfileID = Convert.ToInt32(rdr["DeeProfileID"]) }; resultslistden.Add(results); } } } return resultslistden; //return jsonlist; //return resultslistden.ToJSON2(); }
Please assist. Thank you in advance. Any guidance would be helpful.