using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;namespace datagrid
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.Button button1; private string connection="workstation id =localhost; Integrated Security=SSPI;database=jxcbook";
private string sendTableName="商品清单";
private string sendSQL="select * from 商品清单";
private DataSet ds=new DataSet();
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
SqlConnection myConnection=new SqlConnection(connection);
SqlDataAdapter da=new SqlDataAdapter(sendSQL,myConnection);
this.ds.Clear();
da.Fill(ds,sendTableName);
this.dataGrid1.DataSource=ds.Tables[0]; //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.button1 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(8, 80);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(280, 144);
this.dataGrid1.TabIndex = 0;
//
// button1
//
this.button1.Location = new System.Drawing.Point(56, 32);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(64, 24);
this.button1.TabIndex = 1;
this.button1.Text = "查询";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.button1);
this.Controls.Add(this.dataGrid1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void btn_Search_Click(object sender, System.EventArgs e)
{
//显示当查询货号为001时的商品信息,代码如何写,急盼
}
}
}
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;namespace datagrid
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.Button button1; private string connection="workstation id =localhost; Integrated Security=SSPI;database=jxcbook";
private string sendTableName="商品清单";
private string sendSQL="select * from 商品清单";
private DataSet ds=new DataSet();
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
SqlConnection myConnection=new SqlConnection(connection);
SqlDataAdapter da=new SqlDataAdapter(sendSQL,myConnection);
this.ds.Clear();
da.Fill(ds,sendTableName);
this.dataGrid1.DataSource=ds.Tables[0]; //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.button1 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(8, 80);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(280, 144);
this.dataGrid1.TabIndex = 0;
//
// button1
//
this.button1.Location = new System.Drawing.Point(56, 32);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(64, 24);
this.button1.TabIndex = 1;
this.button1.Text = "查询";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.button1);
this.Controls.Add(this.dataGrid1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void btn_Search_Click(object sender, System.EventArgs e)
{
//显示当查询货号为001时的商品信息,代码如何写,急盼
}
}
}
解决方案 »
- 只能允许查看文件,不能保存和打印,如何实现?
- 本机框架位于调用堆栈之上,因此无法计算表达式的值。
- 谁能把这段xml通过visual c sharp 调用从存储过程生成数据表[每天中午12:00 - 13:00在线]
- 请问各位C#高手Random类如何使用!
- 各位看看下面的代码有什么错
- 奇怪的弹出窗口问题,哪位仁兄帮帮忙
- merge问题
- 为什么窗体关闭两次才能关掉??
- 看了个程序<%@ import namespace="System.Data.SQL"%>和SQLDataSetCommand在FrameWork怎么没有亚
- 心情好,散分,快,马上结贴
- 2003开发的项目,我把它转入2005环境下开发,在编译后为何窗体最大化无效?
- c#如何检查端口被使用了
myDataView.RowFilter = "货号='001'";//Add your filter here
DataView dv = new DataView(ds.Tables["yourTableName"]);// Filter the dataview to only show customers with the CustomerID of ALFKI
dv.RowFilter = "货号='001'";//Add your filter here
dv.RowStateFilter = DataViewRowState.ModifiedCurrent;yourDataGrid.DataSource = dv;
dv.RowstateFilter=DataViewRowState.ModifiedCurrend;此句有点误。
不过没有这句话也能实现。多谢!!以后请多多关照!!
用SQL中的select ...from where 语句怎么实现?