SqlConnection cnn = new SqlConnection("Data Source=.;Initial Catalog=SSMS;Integrated Security=SSPI");
SqlCommand cmd3 = new SqlCommand("select * from Score where SID = '" + toolStripTextBox1.Text.Trim() + "'and CID='" + toolStripTextBox2.Text.Trim() + "'", cnn);
cnn.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd3);
DataTable dt = new DataTable();
da.Fill(dt);
this.dataGridView1.DataSource = dt;
this.toolStripTextBox3.Text = this.dataGridView1.CurrentRow.Cells[2].Value.ToString();
this.toolStripTextBox4.Text = this.dataGridView1.CurrentRow.Cells[3].Value.ToString();
为什么dataGridView1中没有显示数据啊?
SqlCommand cmd3 = new SqlCommand("select * from Score where SID = '" + toolStripTextBox1.Text.Trim() + "'and CID='" + toolStripTextBox2.Text.Trim() + "'", cnn);
cnn.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd3);
DataTable dt = new DataTable();
da.Fill(dt);
this.dataGridView1.DataSource = dt;
this.toolStripTextBox3.Text = this.dataGridView1.CurrentRow.Cells[2].Value.ToString();
this.toolStripTextBox4.Text = this.dataGridView1.CurrentRow.Cells[3].Value.ToString();
为什么dataGridView1中没有显示数据啊?
BindingSource dataSrc = new BindingSource();
dataSrc.DataSource = dt;
然后指向这个
dataSrc
this.GridView1.DataBind();
错误 1、 “System.Windows.Forms.DataGridView”并不包含“displayMember”的定义、
错误 “System.Windows.Forms.DataGridView”并不包含“DataBind”的定义
{
using (cmd = new SqlCommand("select * from Student where SID='" + toolStripTextBox1.Text.Trim() + "'", cn))
{
da = new SqlDataAdapter(cmd);
dt = new DataTable();
da.Fill(dt);
this.dataGridView1.DataSource = dt;
this.toolStripTextBox1.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
this.textBox1.Text = this.dataGridView1.CurrentRow.Cells[1].Value.ToString();
this.textBox8.Text = this.dataGridView1.CurrentRow.Cells[3].Value.ToString();
我这个可以啊
SqlCommand cmd3 = new SqlCommand("select * from Score where SID = '" + toolStripTextBox1.Text.Trim() + "'and CID='" + toolStripTextBox2.Text.Trim() + "'", cnn);
cnn.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd3);
DataTable dt = new DataTable();
da.Fill(dt);
this.dataGridView1.DataSource = dt;
this.toolStripTextBox3.Text = this.dataGridView1.CurrentRow.Cells[2].Value.ToString();
this.toolStripTextBox4.Text = this.dataGridView1.CurrentRow.Cells[3].Value.ToString();
又能解决问题的啊??????
SqlConnection cnn = new SqlConnection("Data Source=.;Initial Catalog=SSMS;Integrated Security=SSPI");
SqlCommand cmd3 = new SqlCommand("select * from Score where SID = '" + toolStripTextBox1.Text.Trim() + "'and CID='" + toolStripTextBox2.Text.Trim() + "'", cnn);
cnn.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd3);
DataTable dt = new DataTable();
da.Fill(dt);
bindingSource1.DataSource = dt;
this.dataGridView1.DataSource = bindingSource1;
看的MSDN上的
多次一举,直接this.dataGridView1.DataSource = dt就完了
MSDN上的例子也是要那个bindingSource的
不信可以去看
我昨天晚上才看了
http://msdn.microsoft.com/zh-cn/library/system.windows.forms.datagridview.datasource.aspx
自己看吧
SqlCommand cmd3 = new SqlCommand("select * from news where classid = '" + toolStripTextBox1.Text.Trim() + "'and newsid='" + toolStripTextBox2.Text.Trim() + "'", conn);
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd3);
DataTable dt = new DataTable();
da.Fill(dt);
this.dataGridView1.DataSource = dt; //SqlDataAdapter da = new SqlDataAdapter("select * from News where classid='329'", conn);
this.toolStripTextBox3.Text = this.dataGridView1.CurrentRow.Cells[2].Value.ToString();
this.toolStripTextBox4.Text = this.dataGridView1.CurrentRow.Cells[4].Value.ToString();
运行过了,没有问题,除了第一句我是用sa登录的,第二句改了表名和自段名,其余完全一样。你试试你的查询语句能查出结果吗