请教一个获取数据库的程序
这个要求是获取数据库结构
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private DataTable Database()
{
using (SqlConnection con = new SqlConnection("server=(local);uid=sa;pwd=123456;database=master"))
{
SqlDataAdapter da = new SqlDataAdapter("select name from sysdatabases", con);
DataTable dt = new DataTable("sysdatabases");
da.Fill(dt);
return dt;
}
}
private void button1_Click(object sender, EventArgs e)
{
this.dataGridView1.DataSource = null;
string strDatabase = this.comboBox1.Text.ToString();
using (SqlConnection con = new SqlConnection("server=(local);uid=sa;pwd=123456;database='" + strDatabase + "'"))
{
SqlDataAdapter da = new SqlDataAdapter("select name from sysobjects where type='U' and name<>'dtproperties'", con);
DataTable dt = new DataTable("sysobjects");
da.Fill(dt);
this.listBox1.DataSource = dt.DefaultView;
this.listBox1.DisplayMember = "name";
this.listBox1.ValueMember = "name";
}
}
}
}
其中 本来这句string strDatabase = this.comboBox1.Text.ToString(); 前面的string 是没有的
不知道这个如何改 请教~!程序才能正常获取到数据。