using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
string strDatabase = null;
public Form1()
{
InitializeComponent();
} private DataTable Database()
{
using(SqlConnection conn=new SqlConnection("server=localhost;database=master;uid=sa;pwd=chy19900909"))
{
SqlDataAdapter da = new SqlDataAdapter("select name from sysdatabases",conn);
DataTable dt = new DataTable("sysdatabases");
da.Fill(dt);
return dt;
}
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.DataSource = Database();
comboBox1.DisplayMember = "name";
comboBox1.ValueMember = "name";
} private void button1_Click(object sender, EventArgs e)
{
this.dataGridView1.DataSource=null;
strDatabase = this.comboBox1.Text.ToString();
using(SqlConnection conn=new SqlConnection("server=localhost;database='"+strDatabase+"';uid=sa;pwd=chy19900909"))
{
SqlDataAdapter da = new SqlDataAdapter("select name from sysobjects where type='U' and name<>'dtproperties'",conn);
DataTable dt = new DataTable("sysobjects");
da.Fill(dt);
listBox1.DataSource = dt.DefaultView;
listBox1.DisplayMember = "name";
listBox1.ValueMember="name"; } }
private void listBox1_Click(object sender, EventArgs e)
{
string strTableName = this.listBox1.SelectedValue.ToString();
using(SqlConnection conn=new SqlConnection("server=localhost;database='"+strDatabase+"';uid=sa;pwd=chy19900909"))
{
string strSql = "select name 字段名, xusertype 类型编号, length 长度 into hy_Linshibiao from syscolumns where id=object_id('" + strTableName + "') ";
strSql += "select name 类型,xusertype 类型编号 into angel_Linshibiao from systypes where xusertype in (select xusertype from syscolumns where id=object_id('" + strTableName + "'))";
conn.Open();
SqlCommand cmd = new SqlCommand(strSql, conn);
cmd.ExecuteNonQuery();
conn.Close(); SqlDataAdapter da = new SqlDataAdapter("select 字段名,类型,长度 from hy_Linshibiao t,angel_Linshibiao b where t.类型编号=b.类型编号", conn);
DataTable dt = new DataTable();
da.Fill(dt);
this.dataGridView1.DataSource = dt.DefaultView; SqlCommand cmdnew = new SqlCommand("drop table hy_Linshibiao,angel_Linshibiao", conn);
conn.Open();
cmdnew.ExecuteNonQuery();
conn.Close();
} }
}
}
数据库databaseobjectstringserver
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
string strDatabase = null;
public Form1()
{
InitializeComponent();
} private DataTable Database()
{
using(SqlConnection conn=new SqlConnection("server=localhost;database=master;uid=sa;pwd=chy19900909"))
{
SqlDataAdapter da = new SqlDataAdapter("select name from sysdatabases",conn);
DataTable dt = new DataTable("sysdatabases");
da.Fill(dt);
return dt;
}
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.DataSource = Database();
comboBox1.DisplayMember = "name";
comboBox1.ValueMember = "name";
} private void button1_Click(object sender, EventArgs e)
{
this.dataGridView1.DataSource=null;
strDatabase = this.comboBox1.Text.ToString();
using(SqlConnection conn=new SqlConnection("server=localhost;database='"+strDatabase+"';uid=sa;pwd=chy19900909"))
{
SqlDataAdapter da = new SqlDataAdapter("select name from sysobjects where type='U' and name<>'dtproperties'",conn);
DataTable dt = new DataTable("sysobjects");
da.Fill(dt);
listBox1.DataSource = dt.DefaultView;
listBox1.DisplayMember = "name";
listBox1.ValueMember="name"; } }
private void listBox1_Click(object sender, EventArgs e)
{
string strTableName = this.listBox1.SelectedValue.ToString();
using(SqlConnection conn=new SqlConnection("server=localhost;database='"+strDatabase+"';uid=sa;pwd=chy19900909"))
{
string strSql = "select name 字段名, xusertype 类型编号, length 长度 into hy_Linshibiao from syscolumns where id=object_id('" + strTableName + "') ";
strSql += "select name 类型,xusertype 类型编号 into angel_Linshibiao from systypes where xusertype in (select xusertype from syscolumns where id=object_id('" + strTableName + "'))";
conn.Open();
SqlCommand cmd = new SqlCommand(strSql, conn);
cmd.ExecuteNonQuery();
conn.Close(); SqlDataAdapter da = new SqlDataAdapter("select 字段名,类型,长度 from hy_Linshibiao t,angel_Linshibiao b where t.类型编号=b.类型编号", conn);
DataTable dt = new DataTable();
da.Fill(dt);
this.dataGridView1.DataSource = dt.DefaultView; SqlCommand cmdnew = new SqlCommand("drop table hy_Linshibiao,angel_Linshibiao", conn);
conn.Open();
cmdnew.ExecuteNonQuery();
conn.Close();
} }
}
}
数据库databaseobjectstringserver
解决方案 »
- .net修改文件内的指定字符
- 想做一个图片处理的程序
- 用vs2008做的asp.net程序,我要把系统中的一个程序集(.dll),添加到我的项目中,然后再从项目中引用,请问怎么实现啊?
- 定义一个CLASS和方法时,在它们前不加修饰符,默认的缺省修饰符是什么呢?
- 为什么DataGrid 要按删除按钮两次 才可以删除
- 关于Windows服务的路径的问题
- 如何恢复BindingSource中被删除的数据?
- sql server 安装错误
- NPOI操作EXCEl相关设置
- 那个水晶报表CrystalReport,是不是需要在客户端安装控件啊?
- C#下怎样操作berkeley db 的游标,急!!!
- XML序列化
这样会创建angel_Linshibiao表,你已经存在angel_Linshibiao表了,所以改成insert into angel_Linshibiao select ... strSql += "insert into angel_Linshibiao select name 类型,xusertype 类型编号 from systypes where
DROP TABLE angel_Linshibiao