刚写了个.net程序 ,系统错误提示:“DataView是命名空间,在此被当作类型使用”,我想问下这是哪里错误了,望各位高人指教下哈,谢谢了,代码如下:
namespace DataView
{
public partial class Form1 : Form
{
string str = "data source=(local); initial catalog=pubs; user id=sa; password=fly";
string strsql = "select * from authors";
SqlDataAdapter da;
DataSet ds;
DataView dv;
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection(str);
cn.Open();
SqlCommand cd = new SqlCommand();
cd.Connection = cn;
cd.CommandText = "select distinct city from authors";
SqlDataReader rdcity = cd.ExecuteReader();
while (rdcity.Read())
{
comboBox1.Items.Add(rdcity["city"]);
}
rdcity.Close();
cn.Close();
} private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
ds = new DataSet();
da = new SqlDataAdapter(strsql,str);
da.Fill(ds, "authors");
dv = new DataView(ds.Tables["authors"]);
dv.RowFilter = "city='" + comboBox1.Text.Trim() + "'";
dataGridView1.DataSource= dv;
radioButton1.Enabled = true;
radioButton2.Enabled = true;
} private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
dv.Sort = "au_id desc";
} private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
dv.Sort = "au_id asc";
}
}
}
namespace DataView
{
public partial class Form1 : Form
{
string str = "data source=(local); initial catalog=pubs; user id=sa; password=fly";
string strsql = "select * from authors";
SqlDataAdapter da;
DataSet ds;
DataView dv;
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection(str);
cn.Open();
SqlCommand cd = new SqlCommand();
cd.Connection = cn;
cd.CommandText = "select distinct city from authors";
SqlDataReader rdcity = cd.ExecuteReader();
while (rdcity.Read())
{
comboBox1.Items.Add(rdcity["city"]);
}
rdcity.Close();
cn.Close();
} private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
ds = new DataSet();
da = new SqlDataAdapter(strsql,str);
da.Fill(ds, "authors");
dv = new DataView(ds.Tables["authors"]);
dv.RowFilter = "city='" + comboBox1.Text.Trim() + "'";
dataGridView1.DataSource= dv;
radioButton1.Enabled = true;
radioButton2.Enabled = true;
} private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
dv.Sort = "au_id desc";
} private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
dv.Sort = "au_id asc";
}
}
}
改成dv = new System.Date.DataView(ds.Tables["authors"]);