当前位置:编程学习 > C#/ASP.NET >>

帮忙看段代码``为什么int bc=cm.Position的值是0

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace Stu
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
SqlConnection sc;
SqlDataAdapter sda;
DataSet ds;

private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.Button load;
private System.Windows.Forms.Button bluepencil;
private System.Windows.Forms.Button delete;
private System.Windows.Forms.Button save;
private System.Windows.Forms.Button exit;
private System.Windows.Forms.CurrencyManager cm;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// 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.load = new System.Windows.Forms.Button();
this.bluepencil = new System.Windows.Forms.Button();
this.delete = new System.Windows.Forms.Button();
this.save = new System.Windows.Forms.Button();
this.exit = 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(0, 0);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(568, 248);
this.dataGrid1.TabIndex = 0;
// 
// load
// 
this.load.Location = new System.Drawing.Point(16, 280);
this.load.Name = "load";
this.load.TabIndex = 1;
this.load.Text = "加载";
this.load.Click += new System.EventHandler(this.load_Click);
// 
// bluepencil
// 
this.bluepencil.Location = new System.Drawing.Point(128, 280);
this.bluepencil.Name = "bluepencil";
this.bluepencil.TabIndex = 2;
this.bluepencil.Text = "编辑";
this.bluepencil.Click += new System.EventHandler(this.bluepencil_Click);
// 
// delete
// 
this.delete.Location = new System.Drawing.Point(248, 280);
this.delete.Name = "delete";
this.delete.TabIndex = 3;
this.delete.Text = "删除";
this.delete.Click += new System.EventHandler(this.delete_Click);
// 
// save
// 
this.save.Location = new System.Drawing.Point(360, 280);
this.save.Name = "save";
this.save.TabIndex = 4;
this.save.Text = "保存";
this.save.Click += new System.EventHandler(this.save_Click);
// 
// exit
// 
this.exit.Location = new System.Drawing.Point(480, 280);
this.exit.Name = "exit";
this.exit.TabIndex = 5;
this.exit.Text = "退出";
this.exit.Click += new System.EventHandler(this.exit_Click);
// 
// Form1
// 
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(568, 333);
this.Controls.Add(this.exit);
this.Controls.Add(this.save);
this.Controls.Add(this.delete);
this.Controls.Add(this.bluepencil);
this.Controls.Add(this.load);
this.Controls.Add(this.dataGrid1);
this.Name = "Form1";
this.Text = "学员信息管理";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main() 
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{
sc=new SqlConnection("server=.;uid=sa;pwd=;database=StudentsDB");
sda =new SqlDataAdapter("select ID as 编号,StuName as 姓名,StuSex as 性别,StuAddress as 地址,StuAge as 年龄 from StudentsInfo",sc);
ds=new DataSet();
sda.Fill(ds,"StudentsInfo");
SqlCommandBuilder scb=new SqlCommandBuilder(sda);
dataGrid1.ReadOnly=true;
bluepencil.Enabled=false;
delete.Enabled=false;
save.Enabled=false;
}

private void load_Click(object sender, System.EventArgs e)
{
bluepencil.Enabled=true;
delete.Enabled=true;
save.Enabled=true;
dataGrid1.DataSource=ds.Tables[0].DefaultView;
}

private void bluepencil_Click(object sender, System.EventArgs e)
{
dataGrid1.ReadOnly=false;
}

private void delete_Click(object sender, System.EventArgs e)
{
cm=(CurrencyManager)this.BindingContext[ds,"StudentsInfo"];
int bc=cm.Position;
ds.Tables[0].Rows[bc].Delete();
}

private void save_Click(object sender, System.EventArgs e)
{
sda.Update(ds,"StudentsInfo");
}

private void exit_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
} --------------------编程问答-------------------- bc 在private void delete_Click(object sender, System.EventArgs e)
这个里面
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,