En iyi yanıtlayıcılar
Tablo Kolon isimlerini, kolon veri tiplerini ve allow null özelliklerini listelemek

Soru
-
Yanıtlar
-
SqlConnection.GetSchema metodunu kullanabilir ve sonucu ListView'inda datasource olarak kullanabilirsin:
void Main() { string strCon = @"server=.\SQLExpress;Trusted_Connection=yes;Database=Northwind"; using (SqlConnection con = new SqlConnection(strCon)) { con.Open(); DataTable c = con.GetSchema("columns",new string[] {"Northwind",null,"Customers",null}); con.Close(); Form f = new ShowDataForm(c,"Columns"); f.ShowDialog(); } } public class ShowDataForm : Form { public ShowDataForm(DataTable tbl, string caption) { this.dgv = new System.Windows.Forms.DataGridView(); this.dgv.Location = new System.Drawing.Point(0, 0); this.dgv.Dock = DockStyle.Fill; this.dgv.DataSource = tbl; this.Text = caption; this.Controls.Add(this.dgv); this.ClientSize = new System.Drawing.Size(1024, 768); } private System.Windows.Forms.DataGridView dgv; }
- Yanıt Olarak Öneren Ali Rıza İnceoğlu 3 Eylül 2012 Pazartesi 11:56
- Yanıt Olarak İşaretleyen Ali Rıza İnceoğlu 6 Eylül 2012 Perşembe 11:13
-
use <veritabanı_adı>
go
select c.name, t.name from sys.columns c
inner join sys.types t
on c.system_type_id = t.system_type_id
where object_id = object_id('tablo_adı')Ekrem Önsoy - MCDBA, MCITP:DBA+DBD, MCSD.Net, MCSE, ITILv3 | http://ekremonsoy.blogspot.com
- Yanıt Olarak Öneren MustafaTorun 1 Eylül 2012 Cumartesi 16:45
- Yanıt Olarak İşaretleyen Ali Rıza İnceoğlu 6 Eylül 2012 Perşembe 11:13
Tüm Yanıtlar
-
use <veritabanı_adı>
go
select c.name, t.name from sys.columns c
inner join sys.types t
on c.system_type_id = t.system_type_id
where object_id = object_id('tablo_adı')Ekrem Önsoy - MCDBA, MCITP:DBA+DBD, MCSD.Net, MCSE, ITILv3 | http://ekremonsoy.blogspot.com
- Yanıt Olarak Öneren MustafaTorun 1 Eylül 2012 Cumartesi 16:45
- Yanıt Olarak İşaretleyen Ali Rıza İnceoğlu 6 Eylül 2012 Perşembe 11:13
-
DECLARE @Table_Name NVARCHAR(100) SET @Table_Name = 'mytablename' SELECT object_name(c.id) AS table_name, c.name AS column_name, t.name AS data_type FROM syscolumns AS c INNER JOIN systypes AS t ON c.xtype = t.xtype WHERE c.id = object_id( @Table_Name )
Böyle bir kod buldum ama bu işimi görür mü ? Bu kodu nasıl kullanabilirim ? Biri bana bu kodun ne işe yaradığını açıklar mı ?- Yanıt Olarak Öneren MustafaTorun 1 Eylül 2012 Cumartesi 16:45
-
benim yazdığım kodun aynısı, ama benim yazdığım SQL 2005 ve sonrası için, senin yazdığın ise 2000'de de çalışır, daha öncekilerde de test etmek gerek.
İki kod da işini görür. Kodu nasıl kullanacağın ise sana kalmış, ama zaten yapmak istediğini belirtmiştin ilk mesajında. Bir ListView veya DataGridView'ü bu kodun sonucuyla (DataSet) doldurabilirsin.
Ekrem Önsoy - MCDBA, MCITP:DBA+DBD, MCSD.Net, MCSE, ITILv3 | http://ekremonsoy.blogspot.com
-
SqlConnection.GetSchema metodunu kullanabilir ve sonucu ListView'inda datasource olarak kullanabilirsin:
void Main() { string strCon = @"server=.\SQLExpress;Trusted_Connection=yes;Database=Northwind"; using (SqlConnection con = new SqlConnection(strCon)) { con.Open(); DataTable c = con.GetSchema("columns",new string[] {"Northwind",null,"Customers",null}); con.Close(); Form f = new ShowDataForm(c,"Columns"); f.ShowDialog(); } } public class ShowDataForm : Form { public ShowDataForm(DataTable tbl, string caption) { this.dgv = new System.Windows.Forms.DataGridView(); this.dgv.Location = new System.Drawing.Point(0, 0); this.dgv.Dock = DockStyle.Fill; this.dgv.DataSource = tbl; this.Text = caption; this.Controls.Add(this.dgv); this.ClientSize = new System.Drawing.Size(1024, 768); } private System.Windows.Forms.DataGridView dgv; }
- Yanıt Olarak Öneren Ali Rıza İnceoğlu 3 Eylül 2012 Pazartesi 11:56
- Yanıt Olarak İşaretleyen Ali Rıza İnceoğlu 6 Eylül 2012 Perşembe 11:13