我希望在点归还这个按键的时候(fillByreadToolStripButton_Click),除了将borrow表中删除一条记录 还希望同时在book和readers表中坐修改
请问该如何做,我以下的代码有时会删错行的数据,有时无法删除,我该怎么修改呢??
amespace Library
{
public partial class ghbook : Form
{
public ghbook()
{
InitializeComponent();
}
//String read = "";
//String bh = ""; private void ghbook_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“libraryDataSet.borrow”中。您可以根据需要移动或移除它。
this.borrowTableAdapter.Fill(this.libraryDataSet.borrow); //read=this.borrowDataGridView.CurrentRow.Cells[0].Value.ToString();
//bh = this.borrowDataGridView.CurrentRow.Cells[1].Value.ToString();
} private void fillByreadToolStripButton_Click(object sender, EventArgs e)
{
try
{
this.borrowTableAdapter.FillByread(this.libraryDataSet.borrow, readersbhToolStripTextBox.Text);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
} } private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
{
try
{ this.Validate(); String conn = "Dsn=Library;uid=sa;pwd=261903659;app=Microsoft® Visual Studio® 2005;wsid=TT;database=Library";
OdbcConnection connstring = new OdbcConnection(conn); MessageBox.Show(this.borrowDataGridView.CurrentRow.Cells[0].Value.ToString());
//修改readers表中已经借了几本书的值使其 -1
String sqlchange = "UPDATE readers set yjsl=yjsl-1 where BH='" + this.borrowDataGridView.CurrentRow.Cells[0].Value.ToString() + "'";
OdbcCommand comm1 = new OdbcCommand(sqlchange, connstring);
connstring.Open();
comm1.ExecuteNonQuery();
connstring.Close(); MessageBox.Show(this.borrowDataGridView.CurrentRow.Cells[1].Value.ToString()); //修改book表中置状态为 归还
String sqlchange2 = "UPDATE book set zt='归还' where bh='" + this.borrowDataGridView.CurrentRow.Cells[0].Value.ToString() + "'";
OdbcCommand comm2 = new OdbcCommand(sqlchange2, connstring);
connstring.Open();
comm2.ExecuteNonQuery();
connstring.Close();
this.borrowBindingSource.EndEdit();
this.borrowTableAdapter.Update(this.libraryDataSet.borrow); MessageBox.Show("书籍归还成功!");
}
catch
{
MessageBox.Show("归还失败!");
}
} private void fillByToolStripButton_Click(object sender, EventArgs e)
{
try
{
this.borrowTableAdapter.FillBy(this.libraryDataSet.borrow);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
} }
请问该如何做,我以下的代码有时会删错行的数据,有时无法删除,我该怎么修改呢??
amespace Library
{
public partial class ghbook : Form
{
public ghbook()
{
InitializeComponent();
}
//String read = "";
//String bh = ""; private void ghbook_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“libraryDataSet.borrow”中。您可以根据需要移动或移除它。
this.borrowTableAdapter.Fill(this.libraryDataSet.borrow); //read=this.borrowDataGridView.CurrentRow.Cells[0].Value.ToString();
//bh = this.borrowDataGridView.CurrentRow.Cells[1].Value.ToString();
} private void fillByreadToolStripButton_Click(object sender, EventArgs e)
{
try
{
this.borrowTableAdapter.FillByread(this.libraryDataSet.borrow, readersbhToolStripTextBox.Text);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
} } private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
{
try
{ this.Validate(); String conn = "Dsn=Library;uid=sa;pwd=261903659;app=Microsoft® Visual Studio® 2005;wsid=TT;database=Library";
OdbcConnection connstring = new OdbcConnection(conn); MessageBox.Show(this.borrowDataGridView.CurrentRow.Cells[0].Value.ToString());
//修改readers表中已经借了几本书的值使其 -1
String sqlchange = "UPDATE readers set yjsl=yjsl-1 where BH='" + this.borrowDataGridView.CurrentRow.Cells[0].Value.ToString() + "'";
OdbcCommand comm1 = new OdbcCommand(sqlchange, connstring);
connstring.Open();
comm1.ExecuteNonQuery();
connstring.Close(); MessageBox.Show(this.borrowDataGridView.CurrentRow.Cells[1].Value.ToString()); //修改book表中置状态为 归还
String sqlchange2 = "UPDATE book set zt='归还' where bh='" + this.borrowDataGridView.CurrentRow.Cells[0].Value.ToString() + "'";
OdbcCommand comm2 = new OdbcCommand(sqlchange2, connstring);
connstring.Open();
comm2.ExecuteNonQuery();
connstring.Close();
this.borrowBindingSource.EndEdit();
this.borrowTableAdapter.Update(this.libraryDataSet.borrow); MessageBox.Show("书籍归还成功!");
}
catch
{
MessageBox.Show("归还失败!");
}
} private void fillByToolStripButton_Click(object sender, EventArgs e)
{
try
{
this.borrowTableAdapter.FillBy(this.libraryDataSet.borrow);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
} }
解决方案 »
- Socket下的“由于目标机器积极拒绝,无法连接”错误
- Web应用程序中,想把文本拷贝到系统剪贴板的问题,急!
- 讨论贴:多核技术是否又要带来软件开发革命性变化?(跟C#也有关,贴不长)
- 在OWC中如何显示数值?
- 对于MS又推出C#的下一代语言```大家有什么看法```
- 请教DateTime中的Ticks属性是什么意思?
- 2008年的奥运会,我们程序员可以做些什么,除了看比赛?
- 如何将这样的文本数据导入数据库?????
- 请问:我有些C的底子,想转C#,看什么书好?
- c# serialPort.DataReceived 事件的触发问题
- c#里面如何将字符串转换成整型
- gridview控件按回车会自动新增一行
this.dataGridView1.SelectedRows[0]
this.dataGridView1.CurrentRow.Cells[0].Value