| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2748 人关注过本帖
标题:[求助]在DGV中拋出异常"索引0沒有值"
只看楼主 加入收藏
crazymk
Rank: 1
等 级:新手上路
威 望:1
帖 子:343
专家分:0
注 册:2007-8-30
收藏
得分:0 
沒有用過Filter來篩選。
解決以後麻煩告知一下經驗

すばらしいコードを書き出すのは楽しい事です
2007-10-09 15:23
C_B_Lu
Rank: 1
等 级:新手上路
威 望:1
帖 子:453
专家分:0
注 册:2006-1-10
收藏
得分:0 
问题仍未解决,再顶一下...

帮助那些真正需要帮助的人,是对帮助你的人最好的回报!
2007-10-10 08:37
C_B_Lu
Rank: 1
等 级:新手上路
威 望:1
帖 子:453
专家分:0
注 册:2006-1-10
收藏
得分:0 
问题仍未解决,再顶一下...

帮助那些真正需要帮助的人,是对帮助你的人最好的回报!
2007-10-13 09:52
C_B_Lu
Rank: 1
等 级:新手上路
威 望:1
帖 子:453
专家分:0
注 册:2006-1-10
收藏
得分:0 

問題仍未解決﹐現附上部份代碼﹐請大蝦們幫看看
1﹒綁定數据到DGV中的代碼
private void bindingQuotationList(string strSupplierID)
{
if (ds.Tables["QuotationList"] != null)
{
ds.Tables["QuotationList"].Clear();
}
SqlCommand cmdQuotationList = new SqlCommand();
cmdQuotationList.CommandText = "SELECT * FROM [ViewQuotation] WHERE [SupplierID] = @sid ORDER BY [QuotationID]";
cmdQuotationList.CommandType = CommandType.Text;
cmdQuotationList.Parameters.Add(new SqlParameter("@sid", strSupplierID));
cmdQuotationList.Connection = conn;
sdaQuotationList = new SqlDataAdapter(cmdQuotationList);
sdaQuotationList.Fill(ds, "QuotationList");
bsQuotationList.DataSource = ds.Tables["QuotationList"];
dgvQuotationList.DataSource = bsQuotationList;
}
2.執行刪除的代碼﹕

private void tsbDelete_Click(object sender, EventArgs e)
{
if (dgvQuotationList.Rows.Count == 0)
{
MessageBox.Show("沒有可刪除的記錄!", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (DialogResult.No == MessageBox.Show("确定要刪除料號為[ " + tbPartID.Text.Trim() + " ]的料件單价資料嗎?", "詢問", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
{
return;
}
string strSupplierID = tbSupplierID.Text.Trim();
string strPartID = tbPartID.Text.Trim();
string strMsg = "";
SqlCommand cmd = new SqlCommand();
try
{
if (conn.State != ConnectionState.Open)
{
conn.Open();
}
cmd.Connection = conn;
cmd.CommandText = "Quotation_Delete";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@supplierID", SqlDbType.VarChar, 5);
cmd.Parameters.Add("@partID", SqlDbType.VarChar, 18);
cmd.Parameters.Add("@errorMsg", SqlDbType.VarChar, 200);
cmd.Parameters["@supplierID"].Value = strSupplierID;
cmd.Parameters["@partID"].Value = strPartID;
cmd.Parameters["@errorMsg"].Direction = ParameterDirection.Output;
if (cmd.ExecuteNonQuery() >0)
{
bsQuotationList.RemoveCurrent();
bsQuotationList.EndEdit();
currentState = state.Browse;
ctlState();
}
}
catch
{
strMsg = cmd.Parameters["@errorMsg"].Value.ToString().Trim();
MessageBox.Show(strMsg, "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if (conn.State != ConnectionState.Closed)
{
conn.Close();
}
}
}


帮助那些真正需要帮助的人,是对帮助你的人最好的回报!
2007-10-13 09:56
C_B_Lu
Rank: 1
等 级:新手上路
威 望:1
帖 子:453
专家分:0
注 册:2006-1-10
收藏
得分:0 
再顶一下....

帮助那些真正需要帮助的人,是对帮助你的人最好的回报!
2007-10-17 07:54
crazymk
Rank: 1
等 级:新手上路
威 望:1
帖 子:343
专家分:0
注 册:2007-8-30
收藏
得分:0 
今天活不忙。我來看看能不能現象再現

すばらしいコードを書き出すのは楽しい事です
2007-10-17 08:56
crazymk
Rank: 1
等 级:新手上路
威 望:1
帖 子:343
专家分:0
注 册:2007-8-30
收藏
得分:0 
this.masterTableAdapter.Fill(this.db1DataSet.master);
this.bindingSource1.DataSource = this.db1DataSet.master;
this.dataGridView1.DataSource = this.bindingSource1;


private void button1_Click(object sender, EventArgs e)
{
this.bindingSource1.Filter = "項目 = 100";
}
button1 Click之後數據就篩選沒了,但是沒有出現類似問題,DGV顯示一空白行。

すばらしいコードを書き出すのは楽しい事です
2007-10-17 09:41
C_B_Lu
Rank: 1
等 级:新手上路
威 望:1
帖 子:453
专家分:0
注 册:2006-1-10
收藏
得分:0 
以下是引用crazymk在2007-10-17 9:41:28的发言:
this.masterTableAdapter.Fill(this.db1DataSet.master);
this.bindingSource1.DataSource = this.db1DataSet.master;
this.dataGridView1.DataSource = this.bindingSource1;


private void button1_Click(object sender, EventArgs e)
{
this.bindingSource1.Filter = "項目 = 100";
}
button1 Click之後數據就篩選沒了,但是沒有出現類似問題,DGV顯示一空白行。

我刚依你的方法做了一个简单的例子,也没有问题,但搞不懂我的程序中为什么会是那样子,我得再试试.


帮助那些真正需要帮助的人,是对帮助你的人最好的回报!
2007-11-03 15:03
快速回复:[求助]在DGV中拋出异常"索引0沒有值"
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011606 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved