0
我有一個*。 Mdf數據庫,我將讀入一個GridView ...然後我會給用戶搜索人(按姓氏)的能力。代碼工作正常,直到搜索。當我輸入姓氏並思考搜索時,然後從Catch up中輸出錯誤消息。在* .mdf中搜索不起作用
我是C#的初學者,虛心請求嚴肅的回答。
在此先感謝。
我的代碼
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'baseballDataSet.Players' table. You can move, or remove it, as needed.
this.playersTableAdapter.Fill(this.baseballDataSet.Players);
}
private void search_Click(object sender, EventArgs e)
{
string searchValue = sInput.Text;
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
try
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.Cells[3].Value.ToString().Equals(searchValue))
{
row.Selected = true;
break;
}
}
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
}
什麼錯誤你得到? – DatRid
exc.Message,對象引用未設置爲對象的實例 – user2734182
在哪一行?在'if(row.Cells [3] .Value.ToString()。Equals(searchValue))'? – DatRid