代码如下:
private void btnReturn_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
string strsql = "select * from BorrowBook";
SqlDataAdapter da = new SqlDataAdapter(strsql,this.sqlConnection1);
da.Fill(ds, "还书表");
SqlCommandBuilder sqlcdb = new SqlCommandBuilder(da);
ds.Tables["还书表"].PrimaryKey = new DataColumn[] { ds.Tables["还书表"].Columns["ID"] };
for (int i = 0; i < ds.Tables["还书表"].Rows.Count; i++)
{
if (ds.Tables["还书表"].Rows[i]["ReaderID"].ToString() == this.textReaderID.Text && ds.Tables["还书表"].Rows[i]["BookID"].ToString() == this.textBookID.Text)
{
int dday = System.DateTime.Today.DayOfYear - ((System.DateTime)ds.Tables["还书表"].Rows[i]["ReturnDate"]).DayOfYear;
ds.Tables["还书表"].Rows[i]["FactReturnDate"] = System.DateTime.Today;
da.Update(ds,"还书表");
ds.AcceptChanges();
if (dday > 0)
{
MessageBox.Show(this.textInformation.Text = this.textReaderID.Text + "读者你的" + this.textBookID.Text + "图书已经过期" + Convert.ToString(dday)
+ "天,罚款" + Convert.ToString(dday / 10) + "元RMB", "过期", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
}
}
}
ReturnBook(this.textBookID.Text);
ReturnReader(this.textReaderID.Text);
this.textInformation.Text = this.textReaderID.Text + "归还图书" + this.textBookID.Text + "成功";
}以上代码是想实现更新数据表“BorrowBook”中的FactReturnDate字段,通过“ds.Tables["还书表"].Rows[i]["FactReturnDate"] = System.DateTime.Today;”来获取系统时间,但是通过以上这个函数却更新不了,不知道哪里出错了?
private void btnReturn_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
string strsql = "select * from BorrowBook";
SqlDataAdapter da = new SqlDataAdapter(strsql,this.sqlConnection1);
da.Fill(ds, "还书表");
SqlCommandBuilder sqlcdb = new SqlCommandBuilder(da);
ds.Tables["还书表"].PrimaryKey = new DataColumn[] { ds.Tables["还书表"].Columns["ID"] };
for (int i = 0; i < ds.Tables["还书表"].Rows.Count; i++)
{
if (ds.Tables["还书表"].Rows[i]["ReaderID"].ToString() == this.textReaderID.Text && ds.Tables["还书表"].Rows[i]["BookID"].ToString() == this.textBookID.Text)
{
int dday = System.DateTime.Today.DayOfYear - ((System.DateTime)ds.Tables["还书表"].Rows[i]["ReturnDate"]).DayOfYear;
ds.Tables["还书表"].Rows[i]["FactReturnDate"] = System.DateTime.Today;
da.Update(ds,"还书表");
ds.AcceptChanges();
if (dday > 0)
{
MessageBox.Show(this.textInformation.Text = this.textReaderID.Text + "读者你的" + this.textBookID.Text + "图书已经过期" + Convert.ToString(dday)
+ "天,罚款" + Convert.ToString(dday / 10) + "元RMB", "过期", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
}
}
}
ReturnBook(this.textBookID.Text);
ReturnReader(this.textReaderID.Text);
this.textInformation.Text = this.textReaderID.Text + "归还图书" + this.textBookID.Text + "成功";
}以上代码是想实现更新数据表“BorrowBook”中的FactReturnDate字段,通过“ds.Tables["还书表"].Rows[i]["FactReturnDate"] = System.DateTime.Today;”来获取系统时间,但是通过以上这个函数却更新不了,不知道哪里出错了?
解决方案 »
- Access通过Sql语句创建数据库
- 我是初学者.我在VS2003下做的一个很简单的aspx页放到VS2005的环境出错,为什么?
- 请问Winform下,form1在指定位置ShowDialog后,如何鼠标点击后如果鼠标不在form1上,form1关闭?在form1上,则不关闭form1??
- 如何回退还原ComboBox下拉列表选择值?
- 我从数据库中取出一些数据,形式诸如:统计/查询/打印/../../../
- 如何获得一个url的创建时间?
- 动态生成Timer控件,分别用来向串口发送接收数据,现在只有最后一个打开的串口能收发数据!
- 昨天偷偷拜访我机器的人
- C#.net连接MSSQL数据库和连接access2003数据库的区别?在线等(只有100分了,麻烦大家帮帮我!!)
- 怎么样一个个的输入元素的值(有内容!)??拜托了!
- 使用c#.net,接收pop3附件问题
- listbox的问题
MSSQLConn conn = DBConn.MSSQL;
SqlConnection m_conn = conn.Conn; SqlCommand UpdateH = new SqlCommand("t_BJ_BJUpdate", m_conn);
UpdateH.CommandType = CommandType.StoredProcedure;
SqlCommand insertM = new SqlCommand("t_BJ_BJsInsert", m_conn);
insertM.CommandType = CommandType.StoredProcedure;
SqlDataAdapter sda = new SqlDataAdapter();
sda.InsertCommand = insertM;
sda.TableMappings.Add("Bs", "t_BjBills");
SqlParameterCollection sqlp = insertM.Parameters; sqlp.Add("@BJID", SqlDbType.Int);
sqlp.Add("@inid", SqlDbType.Int, 4, "inid");
sqlp.Add("@InvID", SqlDbType.Int, 4, "InvID");
sqlp.Add("@Qty", SqlDbType.Money, 8, "Qty");
sqlp.Add("@Cost", SqlDbType.Money, 8, "Cost");
sqlp.Add("@ReBatch", SqlDbType.NVarChar, 30, "ReBatch");
sqlp.Add("@Quo", SqlDbType.Float, 8, "Quo");
sqlp.Add("@TaxP", SqlDbType.Money, 8, "TaxP");
sqlp.Add("@SumP", SqlDbType.Money, 8, "SumP");
sqlp.Add("@Term", SqlDbType.NVarChar, 4, "Term");
sqlp.Add("@RQty", SqlDbType.Money, 8, "RQty");
sqlp.Add("@RSumP", SqlDbType.Money, 8, "RSumP");
sqlp.Add("@RDate", SqlDbType.DateTime, 8, "RDate");
sqlp.Add("@CusID", SqlDbType.Int);
sqlp.Add("@Memo", SqlDbType.NVarChar, 40, "Memo");
sqlp["@CusID"].Value = bill.B[0].CusID;
sqlp["@BJID"].Value = bill.B[0].BJID;
代码如下:
private bool BorrowReader(string textReaderID)
{
if (ReaderBorrowedNumber(textReaderID) < 8)
{
this.sqlConnection1.Open();
DataSet ds = new DataSet();
string strsql = "select * from Reader";
SqlDataAdapter da = new SqlDataAdapter(strsql, this.sqlConnection1);
da.Fill(ds, "读者表");
ds.Tables["读者表"].PrimaryKey = new DataColumn[] { ds.Tables["读者表"].Columns["ReaderID"] };
for (int i = 0; i < ds.Tables["读者表"].Rows.Count; i++)
{
if (ds.Tables["读者表"].Rows[i]["ReaderID"].ToString() == textReaderID)
{
ds.Tables["读者表"].Rows[i]["ReaderBorrowedbooks"] =Convert.ToInt32(ds.Tables["读者表"].Rows[i]["ReaderBorrowedbooks"]) + 1;
}
}
SqlCommandBuilder aqlcdb = new SqlCommandBuilder(da);
da.Update(ds, "读者表");
ds.AcceptChanges();
this.sqlConnection1.Close();
return true;
}
else
return false;
}