C# ile MSSQL For XML Kullanımı
1. Sql tarafı
USE [ammaraslantestsql]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Ammar>
-- Description: <Description,Deneme Amaçlı Oluşturulan bir spdir>
-- =============================================
CREATE PROCEDURE [dbo].[prSelectExample]
as
select TaskID, TaskName from Task FOR XML AUTO
GO
2.c# tarafı
public DataTable SPCalistirXML(string prAdi)
{
SqlConnection baglanti = new SqlConnection();
baglanti.ConnectionString = ConfigurationManager.ConnectionStrings["baglan"].ToString();
baglanti.Open();
try
{
SqlDataAdapter veri = new SqlDataAdapter(prAdi, baglanti);
DataTable tablo = new DataTable ();
veri.Fill(tablo);
foreach (DataRow sira1 in tablo.Rows)
{
String ammar = sira1["XML_F52E2B61-18A1-11d1-B105-00805F49916B"].ToString();
}
return tablo;
}
catch
{
DataTable tb = new DataTable ();
tb = null;
return tb;
}
finally
{
baglanti.Close();
}
}
USE [ammaraslantestsql]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Ammar>
-- Description: <Description,Deneme Amaçlı Oluşturulan bir spdir>
-- =============================================
CREATE PROCEDURE [dbo].[prSelectExample]
as
select TaskID, TaskName from Task FOR XML AUTO
GO
2.c# tarafı
public DataTable SPCalistirXML(string prAdi)
{
SqlConnection baglanti = new SqlConnection();
baglanti.ConnectionString = ConfigurationManager.ConnectionStrings["baglan"].ToString();
baglanti.Open();
try
{
SqlDataAdapter veri = new SqlDataAdapter(prAdi, baglanti);
DataTable tablo = new DataTable ();
veri.Fill(tablo);
foreach (DataRow sira1 in tablo.Rows)
{
String ammar = sira1["XML_F52E2B61-18A1-11d1-B105-00805F49916B"].ToString();
}
return tablo;
}
catch
{
DataTable tb = new DataTable ();
tb = null;
return tb;
}
finally
{
baglanti.Close();
}
}
Yorumlar
Yorum Gönder