namespace WindowsApplication2
{
public partial class Form2 : Form
{
SqlDataAdapter sda;
SqlCommandBuilder scb;
DataTable dt = new DataTable();
int id;
public Form2()
{
InitializeComponent();
} private void Form2_Load(object sender, EventArgs e)
{
string sql = "select id as '药品编号',kk as '药品名称' from table";
sda = new SqlDataAdapter(sql, SQL.conStr);
scb = new SqlCommandBuilder(sda);
sda.Fill(dt);
dt.PrimaryKey = new DataColumn[] { dt.Columns["id"] };
dataGridView1.DataSource = dt;
} private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
id = Convert.ToInt16( dataGridView1.SelectedCells[0].Value.ToString());
这里怎么写
} private void delete_Click(object sender, EventArgs e)
{
这里怎么写 }
}
}界面里有个dataGridView绑定表table的两个字段id,kk.还有2个textBox,还有个删除按钮
我的要求是,当双击dataGridView的单元格时,当前2个字段的数值显示在2个textBox中,点击删除按钮时,删除该行。
请各位指教。对DataTable不是很熟悉
{
public partial class Form2 : Form
{
SqlDataAdapter sda;
SqlCommandBuilder scb;
DataTable dt = new DataTable();
int id;
public Form2()
{
InitializeComponent();
} private void Form2_Load(object sender, EventArgs e)
{
string sql = "select id as '药品编号',kk as '药品名称' from table";
sda = new SqlDataAdapter(sql, SQL.conStr);
scb = new SqlCommandBuilder(sda);
sda.Fill(dt);
dt.PrimaryKey = new DataColumn[] { dt.Columns["id"] };
dataGridView1.DataSource = dt;
} private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
id = Convert.ToInt16( dataGridView1.SelectedCells[0].Value.ToString());
这里怎么写
} private void delete_Click(object sender, EventArgs e)
{
这里怎么写 }
}
}界面里有个dataGridView绑定表table的两个字段id,kk.还有2个textBox,还有个删除按钮
我的要求是,当双击dataGridView的单元格时,当前2个字段的数值显示在2个textBox中,点击删除按钮时,删除该行。
请各位指教。对DataTable不是很熟悉
{
textBox1.Text =dataGridView1.Rows[dataGridView1.CurrentRow.Index ].Cells["id"].Value.ToString() ;
}
DataGridView1.Rows.Remove(DataGridView1.CurrentRow)