Solved

Communication with SQL Server through Web Service

Posted on 2011-09-21
8
322 Views
Last Modified: 2013-12-17
Hello Experts,

I have to make a contact's form with: ID, Name, Last name, Telephone etc. I created the tables in SQL Server everything is fine.

I need to connect to SQL Server through Web Service. So the communication between Database and C# should be done with Web service.

Can you please show me sample code? or direct me to a nice and easy tutorial?

Barlet
0
Comment
Question by:barlet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 17

Expert Comment

by:OriNetworks
ID: 36573364
0
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 36573399
Here is good article to update database using web service
http://support.microsoft.com/kb/308056
0
 
LVL 7

Author Comment

by:barlet
ID: 36578836
@sonawanekiran
I really need something like it is in your link but in C# version... I already have the vb code sample..

I have this and tell me if you can change this code from vb to c# (sorry if this is out of the topic!)


Filename IService1.vb

 <OperationContract()>
Function LoadBooks() As DataTable

<OperationContract()>
Function InsertBooks(ByVal title As String, ByVal author As String, ByVal publisher As String,
                            ByVal ISBN As String, ByVal Description As String, ByVal Qty As String,
                            ByVal Price As String) As Boolean

Open in new window



Filename Service1.svc.vb
Public Function SearchBooks(ByVal searchtype As String, ByVal search As String) As DataTable Implements IService1.SearchBooks

Public Function DeleteBooks(ByVal BookID As Integer) As Boolean Implements IService1.DeleteBooks

Open in new window

0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 17

Accepted Solution

by:
sonawanekiran earned 500 total points
ID: 36579078
C#

Filename IService1.vb

[OperationContract]
        public DataTable SearchBooks(string searchtype, string search);

        [OperationContract]
        public bool DeleteBooks(int BookID);

Open in new window



Filename Service1.svc.vb

public DataTable SearchBooks(string searchtype, string search)
        {
            // You code goes here
        }

        public bool DeleteBooks(int BookID)
        {
            // You code goes here
        }

Open in new window

0
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 36579103
OR
1. Open Visual studio
2. File >> New >> Project >> WCF Service (Make sure you should select  C# language)
3. Add above code in respective file
4. You need include System.Data to bring DataTable in scope
0
 
LVL 7

Author Comment

by:barlet
ID: 36579321
seems I cant figure it out...
let me be more clear... I have a Form1 in that form i have DataGridView and a button.
when I click to button should do 'select * from customers' but the query should be in web service side so no sql query is in client application...

I thought I will figure it out with conversion but I am really lost...
0
 
LVL 17

Assisted Solution

by:sonawanekiran
sonawanekiran earned 500 total points
ID: 36579389
You client application should consume the wcf service. In you client application
1) Right click on your project, add service reference
2) Now you are able to make the call to SearchBooks() method of your wcf service
3) DataGridView.DataSource = //  call SearchBooks() method


0
 
LVL 7

Author Closing Comment

by:barlet
ID: 36583895
Thank you for your help...
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question