我用C#做图书管理系统,其中借书控件里面有一条语句刚进for循环就立即跳出来,无语法错误,逻辑错误也找不到,在线求回复!
private void borbtn_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.bkifcklbox.Items.Count; i++)
{
this.bkifcklbox.SetItemChecked(i, false);
} //在借书之前删除在bookinfo所有选中的标记
SqlConnection thisConnection = new SqlConnection("Data Source=localhost;Initial Catalog=Library;Integrated Security=SSPI;");
DataSet thisDataSet = new DataSet();
SqlDataAdapter bookAdapter = new SqlDataAdapter("SELECT * FROM dbo.Book", thisConnection);
SqlCommandBuilder bookBuilder = new SqlCommandBuilder(bookAdapter);
bookAdapter.Fill(thisDataSet, "book");
SqlDataAdapter brrowAdapter = new SqlDataAdapter("SELECT * FROM dbo.User_Book WHERE UserID='+p' ", thisConnection);
SqlCommandBuilder brrowBuilder = new SqlCommandBuilder(brrowAdapter);
brrowAdapter.Fill(thisDataSet, "brrow");
for (int i = 0; i< g; i++)//就是这个for循环,刚进去就跳出来了,里面的语句无法执行
{
if (this.bkifcklbox.GetItemChecked(i)==true)
{
if (h[i] == 0) MessageBox.Show("此书本馆已经全部借出!");
else
{
MessageBox.Show("借阅成功!您可以点击查看借书按钮查看您的已借书目!");
foreach(DataRow thatRow in thisDataSet.Tables["book"].Rows){
if(Convert.ToInt32(thatRow["ID"]) == a[i]){
thatRow["Num"] = h[i] - 1;
bookAdapter.Update(thisDataSet, "book");
}
}
foreach (DataRow theRow in thisDataSet.Tables["brrow"].Rows)
{
if (Convert.ToInt32(theRow["BookID"]) == a[i])
theRow["BroNum"] = Convert.ToInt32(theRow["BroNum"]) + 1;
else
{
DataRow thisRow = thisDataSet.Tables["brrow"].NewRow();
thisRow["UserID"] = p;
thisRow["BookID"] = a[i];
thisRow["BookName"] = b[i];
thisRow["Author"] = c[i];
thisRow["Press"] = d[i];
thisRow["Year"] = f[i];
thisRow["BroNum"] = 1;
thisDataSet.Tables["brrow"].Rows.Add(thisRow);
brrowAdapter.Update(thisDataSet, "brrow");
}
}
}
}
}
}
private void borbtn_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.bkifcklbox.Items.Count; i++)
{
this.bkifcklbox.SetItemChecked(i, false);
} //在借书之前删除在bookinfo所有选中的标记
SqlConnection thisConnection = new SqlConnection("Data Source=localhost;Initial Catalog=Library;Integrated Security=SSPI;");
DataSet thisDataSet = new DataSet();
SqlDataAdapter bookAdapter = new SqlDataAdapter("SELECT * FROM dbo.Book", thisConnection);
SqlCommandBuilder bookBuilder = new SqlCommandBuilder(bookAdapter);
bookAdapter.Fill(thisDataSet, "book");
SqlDataAdapter brrowAdapter = new SqlDataAdapter("SELECT * FROM dbo.User_Book WHERE UserID='+p' ", thisConnection);
SqlCommandBuilder brrowBuilder = new SqlCommandBuilder(brrowAdapter);
brrowAdapter.Fill(thisDataSet, "brrow");
for (int i = 0; i< g; i++)//就是这个for循环,刚进去就跳出来了,里面的语句无法执行
{
if (this.bkifcklbox.GetItemChecked(i)==true)
{
if (h[i] == 0) MessageBox.Show("此书本馆已经全部借出!");
else
{
MessageBox.Show("借阅成功!您可以点击查看借书按钮查看您的已借书目!");
foreach(DataRow thatRow in thisDataSet.Tables["book"].Rows){
if(Convert.ToInt32(thatRow["ID"]) == a[i]){
thatRow["Num"] = h[i] - 1;
bookAdapter.Update(thisDataSet, "book");
}
}
foreach (DataRow theRow in thisDataSet.Tables["brrow"].Rows)
{
if (Convert.ToInt32(theRow["BookID"]) == a[i])
theRow["BroNum"] = Convert.ToInt32(theRow["BroNum"]) + 1;
else
{
DataRow thisRow = thisDataSet.Tables["brrow"].NewRow();
thisRow["UserID"] = p;
thisRow["BookID"] = a[i];
thisRow["BookName"] = b[i];
thisRow["Author"] = c[i];
thisRow["Press"] = d[i];
thisRow["Year"] = f[i];
thisRow["BroNum"] = 1;
thisDataSet.Tables["brrow"].Rows.Add(thisRow);
brrowAdapter.Update(thisDataSet, "brrow");
}
}
}
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货