Solved

Communication with SQL Server through Web Service

Posted on 2011-09-21
8
318 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

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:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

809 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