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
Solved

Communication with SQL Server through Web Service

Posted on 2011-09-21
8
320 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
  • 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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Object Oriented Programming, C#, referencing, scoping. 13 69
Convert datetime to time string 10 28
Help with preventing selection from a combobox 11 34
Name Space error VS2015 1 23
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

840 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