Men XML ni qaytaradigan Saqlangan protsedura yaratdim va men yaratgan usulda ushbu XML ni ham qaytarishni xohlayman.
Menda ikkita muammo bor. Birinchidan, biroz qidiruvdan so'ng, .ExecuteScalar();
dan foydalanish tavsiya etilmaydi, chunki u 2033 belgidan ortiq satrlarni qisqartiradi.
Shunday qilib, men ExecuteXMlReader()
deb nomlangan funktsiyani topdim, lekin .NET 4.0 (C#) da ishlaydigan Visual Web Developer 2010 Express da "System.Data.SqlClient.SqlCommand' does not contain a definition for 'ExecuteXMlReader' and no extension method 'ExecuteXMlReader' accepting a first argument of type 'System.Data.SqlClient.SqlCommand' could be found"
xatosini keltirib chiqarmoqda.
Mana mening saqlangan protseduram:
CREATE PROCEDURE dbo.GETReport
(@ReportDate date)
AS
SELECT * FROM ReportTbl
WHERE ReportDate = @ReportDate
for xml auto, elements
set nocount on;
RETURN
Mana mening usulim:
using System.Data;
using System.Data.SqlClient;
...
//connect
SqlConnection conn = new SqlConnection("Data Source=localhost; User Id=foo; Password=foo; Initial Catalog=Database1");
conn.Open();
//create command
SqlCommand cmd = new SqlCommand("dbo.GETReport", conn);
cmd.Parameters.AddWithValue("@ReportDate", "3/24/2011");
cmd.CommandType = CommandType.StoredProcedure;
DataReader rd = cmd.ExecuteXMlReader(); //this is where error is occuring
//also, it is throwing an error for DataReader as well saying there is no
//type of namespace with that name
rd.Read();
string s = rd.ReadOuterXml(); //also dont know if this is how i should return the XML
Ikkinchidan, ExecuteXMLReader()
muammosiga qo'shimcha ravishda, satrni qaytarish birinchi navbatda XMLni qaytarishning to'g'ri yo'li ekanligini bilmayman... Men uni aylantirishim kerak bo'lgan boshqa ob'ekt turi bormi? Yoki boshqa funktsiyadan foydalanishim kerakmi?
Oldindan rahmat!!