Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,038

HOME > .NET Framework > Forum > .NET จะ return Web Service ค่า Data set จากเว็บเซอร์วิสมันไม่ยอมReturn ครับ


 

[.NET] .NET จะ return Web Service ค่า Data set จากเว็บเซอร์วิสมันไม่ยอมReturn ครับ

 
Topic : 055893

Guest



หหฟ


ดูตามตัวอย่างแล้วมันไม่มีปัญหาอะไรแต่ผมดันมีเกิดพลาดอะไรขึ้นรึเปล่าครับ T-T

ช่วยชี้แนะด้วยครับ พี่ๆทุกท่านที่มีจิตศรัทธา

ด้วยความเคารพ



code webservice
Code (C#)
01.using System;
02.using System.Collections.Generic;
03.using System.Linq;
04.using System.Web;
05.using System.Web.Services;
06.using System.Configuration;
07.using System.Data.SqlClient;
08.using System.Data;
09.using System.ComponentModel;
10.using System.Web.Services.Protocols;
11.using System.Xml.Linq;
12.using System.Web.Configuration;
13. 
14. 
15.[WebService(Namespace = "http://tempuri.org/")]
16.[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
17.// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
18.// [System.Web.Script.Services.ScriptService]
19.public class Service : System.Web.Services.WebService
20.{
21.   
22.    
23.    public Service () {
24. 
25.        //Uncomment the following line if using designed components
26.        //InitializeComponent();
27.    }
28. 
29.    [WebMethod]
30.    public string HelloWorld() {
31.        return "Hello World";
32.    }
33.    [WebMethod]
34.    public string ShowNameAndLastName(string name, string lastname)
35.    {
36.       string name_str = name;
37.       string lastname_str = lastname;
38. 
39.       return string.Format("สวัสดีครับคุณ" + name_str + " " + lastname_str + "เป็นอย่างไรบ้าง");
40.             
41.    
42.    }
43.    [WebMethod]
44.    public string ConnectDB()
45.    {
46. 
47. 
48. 
49. 
50.        string connection13 = ConfigurationManager.ConnectionStrings["sql"].ConnectionString;
51.        SqlConnection ceConn = new SqlConnection(connection13);
52.        SqlCommand ceCmd = ceConn.CreateCommand();
53.        ceCmd.CommandType = CommandType.Text;
54.        ceCmd.CommandText = "select*from customer ";
55. 
56. 
57.        System.Data.DataSet _Ds1 = new System.Data.DataSet();
58.        SqlDataAdapter _npgAdap = new SqlDataAdapter(ceCmd);
59.        _npgAdap.Fill(_Ds1, "moo");
60. 
61.        return _Ds1;
62.         
63.    }
64.     
65.}




Tag : .NET, Ms SQL Server 2008, Web (ASP.NET), WebService, C#

Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-02-11 14:20:36 By : หนอนปทุม View : 1469 Reply : 3
 

 

No. 1



โพสกระทู้ ( 74,059 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Quote:
public string ConnectDB()


คุณประกาศเป็นแบบ String แต่ไป Return DataSet น่ะครับ มันเลย Error
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-02-11 17:02:59 By : webmaster
 

 

No. 2

Guest


ได้แล้วครับอบคุณครับ





Code (C#)
01.using System;
02.using System.Collections.Generic;
03.using System.Linq;
04.using System.Web;
05.using System.Web.Services;
06.using System.Configuration;
07.using System.Data.SqlClient;
08.using System.Data;
09.using System.ComponentModel;
10.using System.Web.Services.Protocols;
11.using System.Xml.Linq;
12.using System.Web.Configuration;
13. 
14. 
15.[WebService(Namespace = "http://tempuri.org/")]
16.[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
17.// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
18.// [System.Web.Script.Services.ScriptService]
19.public class Service : System.Web.Services.WebService
20.{
21.   
22.    
23.    public Service () {
24. 
25.        //Uncomment the following line if using designed components
26.        //InitializeComponent();
27.    }
28. 
29.    [WebMethod]
30.    public string HelloWorld() {
31.        return "Hello World";
32.    }
33.    [WebMethod]
34.    public string ShowNameAndLastName(string name, string lastname)
35.    {
36.       string name_str = name;
37.       string lastname_str = lastname;
38. 
39.       return string.Format("สวัสดีครับคุณ" + name_str + " " + lastname_str + "เป็นอย่างไรบ้าง");
40.             
41.    
42.    }
43.    [WebMethod]
44.    public DataSet ConnectDB()
45.    {
46. 
47. 
48. 
49. 
50.        SqlConnection con = new SqlConnection();
51.        con.ConnectionString = "Data Source= Lincon-PC ;DataBase=Test;Integrated Security=SSPI";
52.        string cmd = "SELECT customer.name, customer.surname, Departments.department FROM customer inner join Departments on customer.id_de = Departments.id_de";
53.        SqlDataAdapter da = new SqlDataAdapter(cmd, con);
54.        DataSet ds = new DataSet();
55.        da.Fill(ds, "ohm");
56.        return ds;
57.         
58.    }
59.    
60.     
61.}




Code (C#)
01.protected void Button1_Click(object sender, EventArgs e)
02.   {
03.        
04.       
05.       localhosts.Service call = new localhosts.Service();
06.       DataSet ds = call.ConnectDB();
07.        
08.        
09.       GridView1.DataSource =ds;
10.       GridView1.DataBind();
11.       GridView2.Visible = false;
12.       GridView1.Visible = true;
13.   }

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-02-15 08:16:58 By : หนอนปทุม
 

 

No. 3



โพสกระทู้ ( 74,059 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook



Go to : ASP.NET กับ Web Service การเขียนเว็บเซอร์วิสรับ-ส่งข้อมูลจาก Database ผ่าน DataSet และ DataTable
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-05-01 20:29:10 By : webmaster
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : .NET จะ return Web Service ค่า Data set จากเว็บเซอร์วิสมันไม่ยอมReturn ครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่