1

i have never found this Answer that how to pass multiple parameters of stored procedure which stroed procedure inside a sharead or static method

i have webservice that need to be as a shared or static method

[WebMethod(EnableSession = true)]
public static SearchParameters[] Select_Search()
{
    List<SearchParameters> JSON = new List<SearchParameters>();
    DataTable dtst = new DataTable();
    dsStockTableAdapters.newSTOCK_LISTTableAdapter List = new dsStockTableAdapters.newSTOCK_LISTTableAdapter();
    string theMake = HttpContext.Current.Session("SelectedMakeValue").ToString();

    dtst = List.GetData(theMake, "0", "0", "0", "0", DisplayType, "", "", "", "Any",
    "", "", "", "", "", 0, "", "", 0, "");

    try {
        foreach (DataRow rdr in dtst.Rows) {
            SearchParameters SRCH = new SearchParameters();
            SRCH.CHASSIS_NO = rdr["CHASSIS_NO"].ToString();
            SRCH.MODEL = rdr["MODEL"].ToString();
            SRCH.color = rdr["color"].ToString();
            SRCH.TRANSMISSION = rdr["TRANSMISSION"].ToString();
            SRCH.DOOR = rdr["DOOR"].ToString();
            SRCH.MAKE = rdr["MAKE"].ToString();
            SRCH.Image1 = rdr["Image1"].ToString();
            SRCH.MODEL_DESCRIPTION = rdr["MODEL_DESCRIPTION"].ToString();

            JSON.Add(SRCH);

        }
    } catch {
    }

    return JSON.ToArray();

}

i want to pass values from different dropdownlist and from textboxes to this stroed procedure below

dtst = List.GetData(theMake, "0", "0", "0", "0", DisplayType, "", "", "", "Any",
    "", "", "", "", "", 0, "", "", 0, "");

something like this

dtst = List.GetData(DropdownList1.SelectedValue, DropDownList2.SelectedValue, DropDownList3.SelectedValue, DropDownList4.SelectedValue, DropDownList5.SelectedValue, DropDownList6.SelectedValue, DropDownList7.SelectedValue, TextBox1.Text, TexBox2.Text);

i have done each and every thing which i could for exmaple i have created property, i used session but with no luck

Simple to listen but hard to implement that how to use control values into shared or static method? is there any easy way from miscrosoft to do this?

Siddiq Baig
  • 586
  • 2
  • 17
  • 37

2 Answers2

0

Well you'll have to use the reference to the instance of your UI.

In VB you'd do it by using the reference: My.Forms.[FormName].DropdownList1.SelectedValue

In C# you CAN use the My namespace: http://msdn.microsoft.com/en-us/library/ms173136.aspx

I think another way that works with both is just accessing [FormName].ActiveForm

But then you need to cast that one to your [FormName] class. Also, the specific Form has to be 'Active' as well.

Let's say you have a form called: MainForm In VB:

With CType(MainForm.ActiveForm, MainForm)
            dtst = List.GetData(.DropdownList1.SelectedValue, .DropDownList2.SelectedValue, .DropDownList3.SelectedValue, .DropDownList4.SelectedValue, .DropDownList5.SelectedValue, .DropDownList6.SelectedValue, .DropDownList7.SelectedValue, .TextBox1.Text, .TexBox2.Text)
End With

Note the dots in front of every non static property in your Form.

In C#, since there is no with statement you'd go about:

MainForm frm = (MainForm)MainForm.ActiveForm;
dtst = List.GetData(frm.DropdownList1.SelectedValue, frm.DropDownList2.SelectedValue, frm.DropDownList3.SelectedValue, frm.DropDownList4.SelectedValue, frm.DropDownList5.SelectedValue, frm.DropDownList6.SelectedValue, frm.DropDownList7.SelectedValue, frm.TextBox1.Text, frm.TexBox2.Text)

If you start haveing more then one Form that can be active you might get problems, and should start looking for another solution... or another application design for that matter.

Normally if i have static procedures in my app, i'd create the instances of my Forms myself, thus i had a reference i can easily access and identify (distinguishing it from other instances)

Edit: I was just made aware, that my post does not have much to do with the question

I am keeping this post until i know whether this thread satisfies: How to get a label value from web user control to a content page using master page

Community
  • 1
  • 1
MrPaulch
  • 1,423
  • 17
  • 21
  • i am not using winform i am using asp.net webform. and by the way dropdonwlist or textboxes are not in any Formview as well in my appliaction – Siddiq Baig Nov 25 '13 at 13:03
  • Ahh yes, should have seen it... Have you checked out this thread? http://stackoverflow.com/questions/3841639/how-to-get-a-label-value-from-web-user-control-to-a-content-page-using-master-pa/3841698#3841698 – MrPaulch Nov 25 '13 at 14:43
0

if you are using the shared or static method of a webservice then there is a solution to pass a multiple parameters value from controls into stored procedure by using jquery...

what i did, i got the control values from jquery and pass that control values to webservice parameters... but i had to keep the same name of both parameters and the key Name (key Data of JSON)...

 var make = $('#<%= ddlMake.ClientID %>').val();
        var color = $('#<%= ddlColor.ClientID %>').val();
        var catagory = $('#<%= ddlCat.ClientID %>').val();
        var model = $('#<%= ddlMakeModel.ClientID %>').val();
        var GlobalLocation = $('#<%= ddlcountry.ClientID %>').val();
        var modelYear = $('#<%= ddlYear.ClientID %>').val();
        var modelYearTill = $('#<%= ddlYearTill.ClientID %>').val();
        var transmission = $('#<%= ddltransmission.ClientID%>').val();
        var minPrice = $('#<%= ddlcost1.ClientID%>').val();
        var maxPrice = $('#<%= ddlcost2.ClientID%>').val();
        var fual_type = $('#<%= rdfuelType.ClientID%>').val();
        var drive = $('#<%= ddldrive.ClientID %>').val();
        var chassis_no = $('#txtChassis_No').val();


        var data = { MAKE: make, COLOR: color, CATAGORY: catagory, MODEL: model, GLOBALLOCATION: GlobalLocation, MODELYEAR: modelYear, MODELYEARTILL: modelYearTill, TRANSMISSION: transmission, MINPRICE: minPrice, MAXPRICE: maxPrice, FUAL_TYPE: fual_type, DRIVE: drive, CHASSIS_NO: chassis_no }
        var jsonData = JSON.stringify(data); 

and then i passed the Same Key name (key,value pair of JSON) in webservice parameters

datatable = myStock.GetData(MAKE, MODEL, COLOR, CATAGORY, GLOBALLOCATION, DisplayType, MODELYEAR, MODELYEARTILL, "", TRANSMISSION, MINPRICE, MAXPRICE, FUAL_TYPE, DRIVE, "", 0, CHASSIS_NO, "", 0, "")
Siddiq Baig
  • 586
  • 2
  • 17
  • 37