Datagrid中的表结构 [英] Table structure In Datagrid
本文介绍了Datagrid中的表结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在datagrid网格中显示sql server表结构.
我想在datagrid中显示表结构.
喜欢
how to display sql server table structure in datagrid grid.
I want to display table structure in datagrid .
Like
Column Name Data type Allow Null
id (Numeric 18,0)
roll_no (Numeric 18,0)
class Varchar(50)
Name Varchar(50)
Fname Varchar(50)
[edit]添加了代码块,删除了虚假的粗体-OriginalGriff [/edit]
[edit]Code block added, spurious bold removed - OriginalGriff[/edit]
推荐答案
Try:
Try:
SELECT column_name, data_type, is_nullable, character_maximum_length FROM information_schema.COLUMNS WHERE table_name='myTable'
这会将表定义作为普通的SQL数据返回-因此,只需像显示其他任何数据一样显示它即可.
That returns the table definition as normal SQL data - so just display it as you would any other data.
您好试试这个,
Hello try this one,
Select t.Table_Schema,
t.Table_Name,
c.Column_Name,
IsNull(c.Column_Default, '') as 'Column_Default',
c.Is_Nullable,
c.Data_Type,
IsNull(c.Character_Maximum_Length, IsNull(Numeric_Precision,'') + IsNull(Numeric_Scale, IsNull(DateTime_Precision,''))) as 'Size'
From Information_Schema.Tables t
Join Information_Schema.Columns c on t.Table_Catalog = c.Table_Catalog
And t.Table_Schema = c.Table_Schema
And t.Table_Name = c.Table_Name
Where t.Table_Type = 'BASE TABLE' and t.Table_Name='your table name'
Order by t.Table_Schema, t.Table_Name, c.Ordinal_Position
C#代码:
c# Code:
void FillData()
{
// 1
// Open connection
using (SqlCeConnection c = new SqlCeConnection(
your connection string))
{
c.Open();
// 2
// Create new DataAdapter
using (SqlCeDataAdapter a = new SqlCeDataAdapter(
"your Query", c))
{
// 3
// Use DataAdapter to fill DataTable
DataTable t = new DataTable();
a.Fill(t);
// 4
// Render data onto the screen
dataGridView1.DataSource = t;
}
}
}
在页面加载中调用此按钮,或单击按钮以此类推...
问候
sarva
Call this in your page load or button click an so on...
regards
sarva
这篇关于Datagrid中的表结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文