如何为存储过程创建wcf? [英] how to create a wcf for the stored procedure ?

查看:110
本文介绍了如何为存储过程创建wcf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



请任何人向我解释如何为存储过程创建wcf服务.我创建了一个存储过程,即Location和PopSublocation.为了在位置下拉列表中获取位置,我编写了类似...的代码.

Hi,

Please any one explain me how to create a wcf service for the stored procedures. I have created a stored procedures namely Location and PopSublocation. For getting the Locations in the location dropdown list I have written the code like...

protected void LocationBind()
        {
            SqlConnection conn = new SqlConnection(connstr);

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "Location";

            conn.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            ddlLocation.DataSource = reader;
            ddlLocation.DataTextField = "Location";
            ddlLocation.DataValueField = "LocationID";
            ddlLocation.DataBind();
            ddlLocation.Items.Insert(0, new ListItem("Select", "-1"));
            conn.Close();
            reader.Close();
        }




然后为了在另一个下拉列表中填充子位置,我创建了另一个存储过程(PopSublocation),它将根据特定的locationID将locationID作为输入,它将填充适当的subLocation.我编写了以下代码来填充下拉列表中的子位置"列表.




Then for populating the sublocation in another drop-down list i have created one more stored procedure(PopSublocation).It will take locationID as input according to the particular locationID it is going to populate the appropriate subLocation. The below code i have written to populate the Sublocation list in the dropdown.

protected void ddlLocation_SelectedIndexChanged(object sender, EventArgs e)
       {
           SqlConnection conn = new SqlConnection(connstr);
           SqlCommand cmd = new SqlCommand();
           cmd.Connection = conn;
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.CommandText = "PopSublocation";
           cmd.Parameters.AddWithValue("@location", Convert.ToInt32(ddlLocation.SelectedValue));
           ddlSublocation.Items.Insert(0, new ListItem("Select", "-1"));
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataSet ds = new DataSet();
           da.Fill(ds);
           ddlSublocation.DataSource = ds.Tables[0];
           ddlSublocation.DataTextField = "Sublocation";
           ddlSublocation.DataValueField = "Sublocation";
           ddlSublocation.DataBind();

                      
       }



现在,我需要为两个存储过程创建一个wcf服务,并在程序中调用它们.为此,请帮帮我,我对这个概念非常陌生.不便之处,敬请原谅.



Now i need to create a wcf service for both stored procedure and call them in the program. Please help me out for this, i am very new for this concept. Sorry for the inconvenience for any errors or not understanding.

推荐答案

这应该可以帮助您入门.

一步一步的WCF初学者小程序 [ ^ ]

我假设您知道如何创建数据库连接.如果您不遵循此
DAL类和Transact-SQL生成器,用于C#和VB.NET [
This should help you get started.

A Step by Step WCF Small Program For Beginners [^]

I assume that you know how to create database connections. If you don''t follow this
DAL Class and Transact-SQL Generator for C# and VB.NET[^]


这篇关于如何为存储过程创建wcf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆