Click here to Skip to main content
15,890,345 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi All,

I have created on WCf Service. Now I just want to add concepts of Ado.net to connect with Sql Server.

Please help me on this.

Thanks in Advance.
Posted
Updated 3-Jul-11 20:28pm
v2

 
Share this answer
 
Comments
Archana Parate 4-Jul-11 2:54am    
Dear..

I know Ado.net but I want use it in WCF Service classes.. Like
[OperationContract]
public DataSet GetSPDataSet(string procedureName, SqlCommand command)
{}

When I pass the Parameter SqlCommand , Service does not work.

Same for Dataset,SqlDataReader, etc..


So Please help me on this...
[no name] 4-Jul-11 3:13am    
The service connects to the database, the client just sends and receives serialized information and knows nothing about the database. You don't want the client to send the sql command and you cannot use parameters that cannot be serialized.
Archana Parate 4-Jul-11 4:20am    
Ok.. It's fine..

Actually I just want to do all transaction like Add,Edit,Update and Delete and Bind GridView through WCF Service.. I'll just call the function of Wcf Service and all transaction will be done through WCF Service. So I just create function like

[OperationContract]
public void FillDropDown(System.Web.UI.WebControls.DropDownList MyDropDown, DataView MyDV)
{
try
{
MyDropDown.DataSource = MyDV;
MyDropDown.DataTextField = MyDV.Table.Columns[1].ColumnName.ToString();
MyDropDown.DataValueField = MyDV.Table.Columns[0].ColumnName.ToString();
MyDropDown.DataBind();
}
catch (Exception ex)
{
throw ex;
}
}

So when I pass Dataview parameter in function , Service does not work..

I am not getting how to solve this problem..

Please reply ASAP with Example
[no name] 4-Jul-11 4:45am    
The dataview cannot be serialized.
In order to send non-serializable objects you need to create a datacontract. Read these articles for more information:

http://www.wcftutorial.net/Data-Contract.aspx[^]
http://msdn.microsoft.com/en-us/library/ms733127.aspx[^]
 
Share this answer
 
HI ,

I have one answer to this question.

Instead of passing dropdownlist to the service ,you can get the dataset from service and bind it to dropdownlist at client end right?
 
Share this answer
 
Hi First you have to define the Method in interface like this
C#
[OperationContract]
DataSet GetEmployees();


This method will return dataset.

Then go to Web.config file and declare your connection

C#
<connectionstrings>
    <add name="FAST" connectionstring="Server=localhost;User id=Ashad-PC\Ashad;Password=;Initial Catalog=FAST_PROD;Integrated Security=SSPI" />
  </connectionstrings>


Then give the implementation for this method in your class

public DataSet GetEmployees()
        {
            SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["FAST"].ConnectionString);
            SqlCommand cmd = new SqlCommand("select * from Employee", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            return ds;
        }


Create a client application,create the proxy of your wcf service and bind the dataset to dropdownlist of gridview or whatever you want.
 
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