它显示错误:表没有主键
DataSet ds = new DataSet("ds1");
DataTable dt = ds.Tables.Add("tblcategory");
string s = textBox1.Text.ToString();
DataRow foundRow = ds.Tables["tblcategory"].Rows.Find(s);
if (foundRow != null)
{
MessageBox.Show(foundRow[0].ToString());
}
答案 0 :(得分:1)
您必须设置表结构,特别是主键列,才能找到Find
行,例如:
var column = dt.Columns.Add("Id", typeof(int));
column.AllowDBNull = false;
column.Unique = true;